Sub topic 12
Navigating the pgAdmin object browser
This chapter assumes you can already connect to a PostgreSQL server and know what databases, schemas and tables are. You should have registered a server in pgAdmin 4 and be able to expand it in the left panel. Here you will learn how that panel maps to the server's structure, how to read the information pgAdmin shows for each object, and where the browser behaves differently from what you might expect.
The browser is a view of the catalogs
The left panel of pgAdmin is the object browser. It shows a tree. Each node is an object that PostgreSQL stores in its system catalogs. pgAdmin builds the tree by running catalog queries when you expand a node, so what you see is only as fresh as your last expansion or refresh.
The tree follows the same hierarchy you met when learning how a server is organized:
Two levels need attention:
- Server Groups are only a folder you create in pgAdmin to organize registrations. PostgreSQL knows nothing about them.
- Login/Group Roles and Tablespaces sit beside Databases, not inside one. Roles belong to the whole server (the cluster), so the same list appears no matter which database you are in.
Connecting lazily
Expanding a server asks for a password if you did not save it. Expanding a database opens a separate connection to that database. PostgreSQL does not let one session switch databases, so pgAdmin opens one connection per database you browse. A database you have not expanded has no pgAdmin connection, and its icon looks greyed out or shows a cross.
This has practical consequences:
- If you browse many databases, you hold many connections. Servers with a low
max_connectionscan run out. - Disconnecting a database (right-click, Disconnect Database) frees its connection without removing the server registration.
- The
\c mydbcommand in psql has no equivalent click. Selecting a database node in the tree is what sets the target of the Query Tool.
Reading the object tree
Databases and schemas
Under a database, the Schemas node lists each schema. public is there by default. System schemas such as pg_catalog and information_schema are hidden unless you turn on Show system objects in the preferences (File, then Preferences, then Browser, then Nodes in recent versions). Hiding them keeps the tree short, but turn the option on when you want to read the catalog views by browsing.
Also look for Catalogs and Extensions nodes under the database. Extensions list installed modules such as pg_stat_statements or pgcrypto, which tells you at a glance what the database depends on.
Tables and what hangs off them
Expanding a table shows sub-collections. These are the ones you will use most:
| Node | What it shows | psql equivalent |
|---|---|---|
| Columns | Name, data type, length, not-null flag, default | `\d orders` |
| Constraints | Primary key, foreign keys, unique and check constraints, exclusion constraints | `\d orders` (bottom section) |
| Indexes | Each index and its definition | `\di`, `\d orders` |
| Triggers | User triggers and their functions | `\d orders` |
| Rules, Policies | Rewrite rules and row-level security policies | `\d+ orders` |
Foreign keys are worth special attention. Open a foreign key node and its Columns tab shows the referenced table and column, and the Action tab shows ON UPDATE and ON DELETE behavior. In psql you would read the same facts from the Foreign-key constraints and Referenced by sections of \d+.
Partitions, views and other collections
Partitioned tables show a Partitions node under the parent. Each partition is a table with its own columns and indexes. Views and materialized views have their own collections. A materialized view's node offers Refresh View, which runs REFRESH MATERIALIZED VIEW and takes locks, so do not use it casually on a busy system.
The Properties panel and the SQL tab
Select any node and the right-hand area shows tabs. The tabs vary by object, but a few appear almost everywhere.
- Dashboard shows activity charts for the server or database. A later chapter covers it.
- Properties shows the object's attributes in a read-only form: owner, comment, size-related settings, and so on.
- SQL shows the
CREATEstatement that would recreate the object. This is generated from the catalogs, not stored text. - Statistics shows per-object counters such as row counts and scan counts. A later chapter covers it.
- Dependencies and Dependents show which objects this one needs and which need it.
The SQL tab is the fastest way to learn how an object is defined, including grants and comments. It is also the safest place to start when you want to change something. Copy the statement into the Query Tool and edit it there instead of using the properties dialog.
Viewing data from the tree
Right-click a table and choose View/Edit Data, then First 100 Rows, Last 100 Rows, All Rows or Filtered Rows. pgAdmin opens a data grid that runs a SELECT for you. The submenu contains these entries, and the choice matters:
- All Rows runs a query without a limit. On a table of tens of millions of rows this can fill the browser's memory. Prefer First 100 Rows.
- Filtered Rows lets you type a
WHEREcondition. It is the quickest way to inspect one customer's orders. - The grid is editable when the table has a primary key. Edits are applied with
UPDATEstatements when you save. A table without a primary key opens read-only because pgAdmin cannot identify a row safely.
Searching and refreshing
The browser does not update itself when another session changes the schema. If a colleague adds a table, you will not see it until you right-click the parent node and choose Refresh, or use the refresh button on the tree toolbar. This is the most common source of "the table is missing" confusion. Confirm with psql, where \dt always queries the live catalog:
psql -d mydb -c '\dt public.*'If the table is listed there but not in pgAdmin, refresh the Tables node.
For large databases, pgAdmin 4 offers Object Search (the search icon in the browser toolbar, or Tools, then Search Objects). It looks up object names, optionally filtered by type, across the database. This replaces a catalog query like the one below when you only need names:
SELECT n.nspname AS schema_name, c.relname AS object_name, c.relkind
FROM pg_class c
JOIN pg_namespace n ON n.oid = c.relnamespace
WHERE c.relname ILIKE '%order%'
AND n.nspname NOT IN ('pg_catalog', 'information_schema')
ORDER BY n.nspname, c.relname;Common problems
- A schema or table appears empty. The role you connected with may lack
USAGEon the schema. PostgreSQL then shows nothing rather than an error in some cases. Check the role in the Login/Group Roles node and the grants on the schema. - Objects exist but are not listed. The tree filters system objects and, in some versions, objects you cannot access. Turn on system objects, then refresh.
- The tree is slow. Each expansion runs catalog queries. A database with tens of thousands of tables makes Tables slow to open. Use Object Search or psql instead of expanding the node.
- Wrong database in the Query Tool. The Query Tool opens against the node you selected. Check the title bar of the tab, which names the database, before you run a statement.
Exercise
A colleague says they created a table public.invoices five minutes ago, and you can query it in psql with \dt public.*, but it is not under Tables in pgAdmin. What is the most likely cause and what do you do? Name one other cause to rule out.
Show answer
The browser tree is cached and does not refresh when other sessions change the schema. Right-click the Tables node (or the schema) and choose Refresh. Another cause is that you are browsing a different database or server registration than the one your colleague used, so check the database name in the tree and compare it with the output of \conninfo in psql.
Exercise
You want to see how the orders table was defined, including its foreign keys and indexes, and then prepare a modified copy of that definition. Which tab do you use in pgAdmin, and why is it better than the properties dialog for making the change?
Show answer
Use the SQL tab on the table node. It shows the generated CREATE statement with constraints and indexes. You can copy it into the Query Tool, edit it, and review the statement before running it, which is safer than changing values in a dialog that applies changes immediately.