Inspect databases, roles, schemas, and tables
PostgreSQL 19.0
Type these commands inside psql after connecting. Backslash commands are processed by the psql client and end at Enter. SQL statements such as SELECT are sent to the server and normally end with a semicolon.
On this page
Where am I connected?
The connection summary shows the current database, role, and connection address or socket.
\conninfo
List databases
Shows the databases on this server. Look for learning_db after creating it. The columns and values can vary with your psql and server versions and locale settings.
\l
Name- The database name, such as learning_db.
Owner- The role that owns the database.
Encoding- The character encoding. UTF8 supports Burmese text.
Locale Provider- Where the database gets its locale behavior. Examples include libc (operating system), icu, and builtin (PostgreSQL).
Collate- The locale setting for comparing and sorting text.
Ctype- The locale setting for character classification and case conversion.
Locale- The locale identifier for providers that use this field, such as ICU. It may be blank for libc.
ICU Rules- Custom ICU collation rules, if configured.
Access privileges- Explicit database privileges for roles, such as CONNECT or CREATE. A blank cell can mean the built-in defaults apply.
Count the databases
This SQL query counts the database entries on the connected server, including template databases.
SELECT count(*) AS database_count FROM pg_database;
List roles
The Role name column contains role names. The Attributes column summarizes the special settings of each role. The built-in administrator on a typical local installation may show the attributes below. Run \du postgres to inspect just that role.
\du
Superuser- Bypasses database permission checks except the right to log in.
Create role- Can create roles and manage eligible roles it administers.
Create DB- Can create databases.
Replication- Can start streaming replication when its login and connection rules also allow it.
Bypass RLS- Bypasses row-level security policies, which can otherwise restrict access to individual rows.
LOGIN / Cannot login- LOGIN lets a role authenticate if its connection rules allow it. A role without LOGIN can still group privileges.
What to expect Example row: postgres | Superuser, Create role, Create DB, Replication, Bypass RLS
List schemas
Shows schemas in the current database. A schema is a namespace for objects such as tables. The examples use the usual public schema.
\dn
List visible tables
Shows tables visible from the current schema search path. Run \dt public.* to explicitly list tables in public. If the database is empty, there may be no tables to show.
\dt
Inspect a table’s columns and constraints
After creating courses in the setup lesson, this displays its columns, data types, defaults, and constraints. Replace courses with the table you want to inspect.
\d courses
Check the connected server version
The SQL function version() reports the server version. In your OS terminal, psql --version reports the client version.
SELECT version();
Find help or exit
Try these one at a time. Use \q last because it returns you to the operating-system terminal. If command output opens in a pager, press q by itself to close the pager and stay in psql.
\?
\h SELECT
\q
\?- Lists psql backslash commands.
\h SELECT- Shows syntax help for the SQL SELECT statement.
\q- Closes psql and returns to your terminal.