How to who uses Redshift in PostgreSQL

Galaxy Glossary

How do I see who is using my Amazon Redshift cluster?

Lists database roles that have accessed or are currently connected to an Amazon Redshift cluster.

Sign up for the latest in SQL knowledge from the Galaxy Team!
Welcome to the Galaxy, Guardian!
Oops! Something went wrong while submitting the form.

Description

What does “who uses Redshift” mean?

It refers to querying system catalog and log tables to discover which database roles have connected, how often, and from where. This helps admins audit usage, control costs, and tighten security.

Which system tables expose Redshift user activity?

Use pg_user (all roles), stl_connection_log (connection history), and stv_recents (current sessions). These tables are available to the superuser by default; grant SELECT on them for read-only insight.

How do I list every role in the cluster?

Query pg_user to return usernames, creation dates, and default schemas. This is the Redshift-compatible equivalent of PostgreSQL’s pg_catalog.pg_user.

Example

SELECT usename AS username,
usesysid AS user_id,
valuntil AS password_expiry
FROM pg_user
ORDER BY username;

How do I find currently connected users?

stv_recents stores one row per active session. Filter by user, database, or client IP.

SELECT usename,
db_name,
starttime AS login_time,
remotehost
FROM stv_recents
WHERE state = 'Running';

How do I audit historical logins?

stl_connection_log keeps a multi-day record of logins and disconnects. Aggregate it to see login counts per user.

SELECT usename,
COUNT(*) AS login_count,
MIN(event_time) AS first_seen,
MAX(event_time) AS last_seen
FROM stl_connection_log
GROUP BY usename
ORDER BY login_count DESC;

How does this apply to an ecommerce database?

Join usage data with business tables to correlate user sessions with workload. For example, link stv_recents to Orders by user-defined tags or set-based access logic.

-- Flag running sessions that touch high-value orders
WITH vip_orders AS (
SELECT customer_id
FROM Orders
WHERE total_amount > 1000
)
SELECT r.usename,
r.remotehost,
o.customer_id
FROM stv_recents AS r
JOIN vip_orders AS o ON r.usename = ('cust_' || o.customer_id::text);

Best practices for monitoring who uses Redshift

1) Automate daily snapshots of stl_connection_log into a permanent table.
2) Grant least-privilege read access to usage views.
3) Schedule alerts when unknown roles connect or when session counts spike.

Common mistakes

Ignoring permission requirements

Many queries fail because non-superusers lack access to system tables. Fix by granting SELECT on the specific catalogs instead of full superuser rights.

Querying only pg_user

pg_user shows role existence, not activity. Always pair it with stv_recents or stl_connection_log for real usage insight.

Want a faster way to explore users?

Galaxy’s AI copilot auto-writes the above queries, names them, and shares them with your team in one click.

Why How to who uses Redshift in PostgreSQL is important

How to who uses Redshift in PostgreSQL Example Usage


-- Which customers' analysts are connected right now?
WITH analysts AS (
  SELECT id, name
  FROM Customers
  WHERE name ILIKE '%Analyst%'
)
SELECT r.usename,
       r.remotehost,
       a.name AS customer_name,
       r.starttime
FROM stv_recents AS r
JOIN analysts AS a ON r.usename = ('cust_' || a.id::text);

How to who uses Redshift in PostgreSQL Syntax


-- List all roles
SELECT usename
FROM pg_user;

-- Show current sessions
SELECT pid,
       usename,
       db_name,
       remotehost,
       starttime
FROM stv_recents;

-- Audit login history
SELECT usename,
       event,
       event_time,
       remotehost
FROM stl_connection_log;

Common Mistakes

Frequently Asked Questions (FAQs)

What retention period does stl_connection_log offer?

Redshift retains roughly two to five days of connection data, depending on cluster load. Persist critical rows to your own audit table for longer retention.

Can I monitor users without superuser rights?

Yes. An admin can grant SELECT on pg_user, stv_recents, and stl_connection_log to a read-only role so analysts can self-serve usage information.

Does querying system tables impact performance?

System tables are lightweight views; simple SELECTs have negligible impact. Avoid expensive pattern scans or cartesian joins during peak workloads.

Want to learn about other SQL terms?

Trusted by top engineers on high-velocity teams
Aryeo Logo
Assort Health
Curri
Rubie
BauHealth Logo
Truvideo Logo
Welcome to the Galaxy, Guardian!
Oops! Something went wrong while submitting the form.