Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

Use l (or list) inside an interactive psql session. From your operating-system shell, run psql -l or psql --list to list databases and exit. If you need SQL for a report or script, connect to any database and query pg_database with SELECT datname FROM pg_database ORDER BY datname;.

Choose the command that matches the job

PostgreSQL provides three practical ways to see the databases in a cluster. The interactive l command is the quickest when you are already inside psql. The shell option psql -l is useful for a one-time terminal check or a script because it prints the list and exits. A SQL query against pg_database gives you control over the columns, filters, and sort order in a report or application.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Route Best use What it provides What you need
l or l+ Human inspection in an active psql session A formatted list with built-in database information; l+ adds size, default tablespace, and description An active psql connection
psql -l or psql --list A one-shot terminal command or shell script Lists databases, then exits; accepts the normal connection options The PostgreSQL client and usable connection details
SELECT ... FROM pg_database Automation, filtering, or a custom report Any columns, predicates, and ordering you specify in SQL A connection and a SQL execution context

Before listing databases

All three methods require a connection to a PostgreSQL server. The client needs a server host, port, user, and database target, either from explicit options or from PostgreSQL’s defaults. If you do not provide a host, PostgreSQL uses a local Unix-domain socket on systems that provide one; on Windows, the default is localhost. If you omit the user, the operating-system user name is used as the default database user. These defaults are convenient for local development but often do not match a remote server or a separately named database role.

When a command fails, first separate a client problem from a server or authentication problem. A missing psql executable is fixed by installing the PostgreSQL client package for your operating system. A connection error means the client was found but could not establish a session, so check the server address, port, service status, and authentication settings. You can make the intended target explicit with the documented connection switches:

#1 Best Overall
Sale
Compressed Air Duster,130000RPM Super Power Cordless Air Duster,Rechargeable Brushless Blower,3 Gear Adjustable Blower with LED Light,Dust Remover for Computer/House/Outdoor/Car
  • Powerful Turbo Fan:CAGIWIRU Electric Air Duster have reached speed up to 130000RPM,Can efficient remove dust and debris.With LED light and Three Adjustable Speed to meet with different cleaning tasks.
  • With Attached USB C Fasting Charging cable.Charing 3 hours,Enjoy up to 240 minutes of use on the lowest setting, For third speed can use for 25mins.with four charging options to meet with your needs.
  • Wide Application: attached 5 different nozzles,making it suitable for a variety of scenes, such as car,pet, pc, keyboards, and other electronic devices. It also serves for office and home clean duster.
  • Handy Design & Portable:Cordless air duster electric nozzle is Light weight and small size, design and comfortable to hold and space saving, convenient to carry around. You can put it in your room or inside the car without taking up space.
  • Economical &Reusable: Built durable materials with a long-lasting battery,our CAGIWIRU air duster it's a sustainable alternative to disposable air cans.
  • -h selects the server host.
  • -p selects the server port.
  • -U selects the database user.
  • -d selects the database to which psql connects.

Listing databases does not require you to connect to each database individually. The catalog that stores the names is cluster-level, so one successful connection is enough to request the cluster’s database list.

List databases inside an interactive psql session

Use l

Start psql with a valid connection, then type the backslash command at the psql prompt:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
l

l is a psql meta-command, not SQL. It asks the client to display the databases known to the connected PostgreSQL server. The standard listing includes each database name, its owner, character-set encoding, and access privileges. After the output appears, you remain in the same psql session and can run another command.

The long spelling is list:

list

list and l perform the same listing operation. Use whichever is easier for you to remember; scripts and runbooks often use the shorter form because it is quick to type, while the long form can be more self-explanatory in a transcript.

Filter names with a psql pattern

You can provide a pattern after the command to restrict the names displayed:

l myapp*

The pattern follows psql‘s pattern rules. In an interactive prompt, the text is passed directly to psql. When you invoke the command through a shell, quote the pattern so the shell does not expand its wildcard before psql receives it. For example, a shell command that passes a meta-command to psql must protect the pattern according to that shell’s quoting rules. The important distinction is that filtering is performed using psql‘s pattern syntax, not by the operating system’s file globbing.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
EVEO® Screen Cleaner Spray Kit (Streak-Free) TV Screen Cleaner for Smart TV, Lcd, LEd, Oled | Computer Screen Cleaner Spray and Wipe Microfiber Cloth - TV, Monitor, Laptop, iPad, Car - 6.7oz 1 Pack
  • Screen Cleaner is Your Screen’s New Bestfriend! - EVEO is proud to present a screen cleaner that’s perfectly suited for your TV. Meet your new screen cleaner, computer screen cleaner, laptop cleaner, iPad cleaner, Macbook,tv cleaner or any other electronic device. Our screen cleaner spray and wipe along with the included plush microfiber cloth, easily removes dust, fingerprints & other smudges on the screen’s surface. Clean effectively for a streak-free screen
  • Gentle on your Screens - Our screen cleaner spray and wipes is compatible to be used even for the most sensitive LCD, LED, CRT, and OLED screens in proper use. Be at ease knowing that this product is compatible with all the major brands: LG, SONY, Samsung, Sharp, iPad, iPhone, Android screens, Kindle, PC monitors - we’ve got you covered! Can be used as LCD screen cleaner, tv cleaner, smart tv screen cleaner, and more
  • Premium Super Soft Plush Microfiber Cloth - Included in this efficient screen cleaning kit. This screen cleaner spray and wipe has our signature plush microfiber cloth specially designed to comply with screens and monitors and leave them streak-free. Has been shown to effectively absorbs stubborn stains, zero streaks, and no fiber shedding. Always use this together with our screen cleaner for the best results
  • Easy-to-Use Screen Cleaner Kit + microfiber cleaning cloth - The EVEO Screen Cleaning Kit will easily be your new favorite tool when it comes to taking care of the things you love most, quick and easy solution for a streak-free screen. Simply screw on the sprayer gun on the screen cleaner bottle. Spray the cleaning liquid onto the microfiber cloth, then wipe the screen until desired cleanliness & shine is achieved.
  • Quality Screen Care Kit Worth Purchasing - Enjoy a convenient Screen Cleaner anytime, anywhere you need it. Your satisfaction is our top priority. We stand behind the quality of our products and that’s why, you shouldn’t be worrying at all. We manufacture the Best Screen Cleaner. and can be used for laptop cleaning kit, laptop screen cleaner, tv screen cleaner for smart tv. MacBook screen cleaner, monitor cleaner or screen cleaner spray for electronic devices with microfiber cleaning cloth

Show expanded information with l+

Add a plus sign when you need more than the normal list:

l+

The expanded form adds the database size, default tablespace, and description. This is useful when you are checking storage usage, confirming where a database’s objects are placed by default, or identifying a database from its administrative description.

Size visibility has a documented permission condition. You can see size information when your current role has CONNECT privilege on the database, when you are a superuser, or when you have the pg_read_all_stats role. A user may therefore see database names and other columns while size values are unavailable. That output difference indicates a visibility or privilege boundary; it does not show that the database has disappeared.

Run a one-shot listing from the operating-system shell

Use psql -l or psql --list

At a shell prompt, run:

psql -l

The long option is equivalent:

psql --list

These options mean “list all available databases, then exit.” You do not need to enter an interactive session or type l. The command connects, prints the list, and returns control to the shell, which makes it suitable for a quick check and for scripts that only need the standard listing.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

With -l, psql connects to the postgres database unless you provide another target with -d or with a positional database argument. The target is the database used to establish the session; the resulting list still describes the databases in the PostgreSQL cluster.

Supply connection details explicitly

Use the normal connection options whenever the server is not reachable through your local defaults:

Rank #3
Sale
BladeHawks RGB Gaming Mouse Pad Extra Large Extended 31.5x12 Inch-Black | LED mouse pad with 14 lighting modes, covers keyboard & mouse, anti-slip rubber base, waterproof surface, USB powered
  • 【Large size】:Measuring 800 x 300 mm/ 31. 5×12 inches, which is wider and taller than others. Large mouse pad can perfectly fit your keyboard and mouse of any size, and there is also ample space for peripherals such as phones, tablets, etc.
  • 【LED backlight mouse pad】:Blade Hawks RGB mouse pad provides 7 static modes and 7 dynamic modes will give you the options you are looking for. Power-off memory function remembers the last lighting mode you selected. The super glow fiber Chroma will give you a colorful gaming setup that you want.
  • 【Anti-slip rubber base】:Made from Natural rubber, this gaming mousepad will firmly grip your desktop, allowing you to enjoy the ultimate precision in the games you are most passionate about. It also comes with a texture that enhances this ability even further.
  • 【Smooth and waterproof surface】: Micro-textured cloth surface, for extremely precise mouse control and a smooth movement. When liquid splashes on the gaming mouse pad, it forms water droplets and slides down. Will not delay your work or gameplay.
  • 【Plug and play】: This mouse and keyboard pad is powered by USB, plug and play, no driver required. One button control light modes. Press one time to change the lighting mode, press twice to change the brightness, press and hold about 3 seconds turn ON/OFF.
psql -h db.example.com -p 5432 -U report_user -l

This example selects host db.example.com, port 5432, and role report_user, then requests the list. You can explicitly choose the connection database as well:

psql -d postgres -l

A positional database name is another way to specify the target:

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
psql postgres -l

For environments that use a PostgreSQL connection URI, the same operation can be written as:

psql postgresql://report_user@db.example.com/postgres -l

The URI identifies the role, host, and connection database; -l still controls the list-and-exit behavior. Use an administrator-approved authentication method for the password. Avoid placing a password directly in a shell command, where it can be saved in shell history or exposed to other users through process inspection.

Understand the result and failure behavior

A successful command prints the database list and exits without leaving an interactive prompt. If the server cannot be reached, the credentials are rejected, or the role cannot establish a usable connection, psql reports the connection error and terminates. The list operation cannot bypass connection authentication: first obtain a valid session, then request the cluster’s databases.

List databases with SQL

Run the catalog query

After connecting to any database, execute:

SELECT datname
FROM pg_database
ORDER BY datname;

The essential catalog query is:

SELECT datname FROM pg_database;

pg_database is a PostgreSQL system catalog at the cluster level. Consequently, the query returns database names for the cluster rather than only objects associated with the database to which your session is currently connected. The ORDER BY datname clause is a useful addition for predictable output: names appear alphabetically instead of relying on an unspecified catalog order. Deterministic ordering is especially helpful when a script compares output over time.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #4
Sale
Vaydeer Wrist Rest for Keyboard and Mouse, Computer Ergonomic Wrist Support Pad, Soft Memory Foam Arm Cushion for Desk, Palm Hand Office Laptop Typing
  • 【Softer and More Comfortable】Vaydeer wrist rest has unique diamond pattern, which is the combination of softness and aesthetics. The materials of wrist rest are improved into higher quality memory foam and covered with silky smooth lycra. The computer wrist rest makes you as comfortable and cushiony as like rest your wrists on clouds.
  • 【Ergonomic Wrist Saver】The wrist rests for keyboard and mouse comes with a 17.32×3.15×0.83 inch keyboard wrist pad and a 5.94×3.15×0.83 inch mouse wrist support. Based on ergonomic design, the unique concave shape is the perfect fit for your wrist joints. The wrist rest pad fits most computer keyboards and laptops, improve hand and wrist posture, release your wrist and arm stress.
  • 【Non-Slip Rubber Bottom】Featuring an anti-skid silicone base on the bottom, this wrist keyboard support stays firmly in place on your desk, preventing the padding from sliding around, ensuring stable and consistent wrist support during extended computer sessions.
  • 【Better Experience & Pain Relief】Our keyboard arm rest is beneficial to alleviate the soreness caused by direct contact and friction between your arm and a hard desk surface, reducing the risk of wrist fatigue or carpal tunnel. The soft texture of memory foam can evenly distribute the pressure around your wrists and provide good support with just enough give.
  • 【Helpful in Multiple Scenarios】Whether you're working, studying, writing, typing, gaming, this keyboard and mouse rest combo is an essential accessory to add comfort and support to your hands and wrists. It’s also a great gift for men, women, family, friend, coworker, gamer, teacher, etc.

Include whether each database accepts connections

To see the allow-connection flag alongside each name, select datallowconn:

SELECT datname, datallowconn
FROM pg_database
ORDER BY datname;

A false value identifies a database configured not to accept ordinary connections. This does not remove the database from the catalog; it explains why a client may be unable to connect to that particular target even though its name appears in the list.

Filter names with SQL

SQL filtering is useful when the naming convention is clear and you want a report that can be extended with more columns later:

SELECT datname
FROM pg_database
WHERE datname LIKE 'app_%'
ORDER BY datname;

Here the LIKE predicate selects names matching the SQL pattern, and the ordering keeps the result stable. SQL patterns are distinct from the patterns accepted by the psql l meta-command, so use the syntax appropriate to the route you chose.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Interactive listing, shell listing, or SQL: which should you use?

The commands expose the same cluster-level inventory, but they serve different workflows.

  • Choose l when you are already working interactively and want a readable table without leaving the session.
  • Choose l+ when the normal columns are not enough and you also need size, default tablespace, or description.
  • Choose psql -l or psql --list when you want a single terminal command that lists and exits, or when a shell script should invoke the built-in listing behavior.
  • Choose SQL against pg_database when you need a custom predicate, a reproducible sort order, the allow-connection flag, or additional catalog-driven reporting.

The first two routes use psql‘s built-in presentation. The SQL route gives you control over exactly which columns are returned and how rows are filtered and ordered. All routes still depend on a successful connection and on the permissions that govern what the connected role can see.

Best Value
Sale
Under Desk Cable Management Tray No Drill, Metal Mesh Cable Management Under Desk with Clamp Mount, 2 Hole Cable Tray with Wire Management and Cord Organizer for Home Office Standing Desk
  • 【No Drill Mounted】Cable management tray can be assembled in as little as 3 minutes or less-simply. Side clips easily clampe the edge of desk, pass through the holes on the sides, and secure excess cables with baskets. Desk cable management supports inward or outward installation to meet your needs in different scenarios, and provides you with great convenience when collecting and organizing wires.
  • 【Rubber Pad Protects Desk】Wire organizer under desk built-in soft rubber pads on the clamp protect your desk from scratches, so you will not damage your furniture or office.
  • 【Sturdy and Beautiful】Cord management under desk is made of high-quality carbon steel and holds about 15 lbs. The wire basket has 2 holes on each side of the tray to enable your cables to pass freely. Cable baskets are suitable for desk thickness use from 0.4" to 2.4".
  • 【Space Saving & Keep Organized】Desk cable management tray holds all your power cords, outlet strips, USB hubs and computer transformers hidden from your feet, and the data cables will not enter the vacuum cleaner to keep your desk clean and tidy. Desk wire organizer is also suitable for use in the kitchen and outdoors.
  • 【Reduce Safety Risks】Cable tray under desk keeps all plugs away from your kids, no more worry about tripping. Using 2 holes wire tray saves extra space, helps you easily cabling and wire protection. The mesh design is not easy to accumulate dust, but avoids safety accidents caused by messy wires.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

End-to-end command examples

Local interactive check

  1. Open a terminal and start psql using your normal local connection settings.
  2. At the psql prompt, enter l.
  3. Read the names, owners, encodings, and privileges in the formatted table.
  4. Enter l+ if you also need sizes, default tablespaces, or descriptions.

Remote one-shot check

  1. Confirm the remote server’s host and port.
  2. Run psql -h db.example.com -p 5432 -U report_user -l, replacing the connection values with the ones approved for your environment.
  3. Complete authentication through the configured PostgreSQL mechanism.
  4. Review the output; the client exits after printing the list.

Deterministic SQL output

  1. Connect to any database on the target cluster.
  2. Execute SELECT datname FROM pg_database ORDER BY datname;.
  3. Use the ordered result in a report or comparison where row order must remain stable.
  4. Add datallowconn or a WHERE datname LIKE ... clause when the report needs connection status or name filtering.

Troubleshooting database listing commands

psql: command not found

The PostgreSQL client is not installed, or its executable is not on the shell’s path. Install the PostgreSQL client package appropriate to your operating system, then verify the installation with:

psql --version

Package names and installation steps differ by operating system, so use the package source maintained for the platform you administer. A server installation and a client installation are separate concerns: you need the psql client on the machine where you run the command, while the server may run locally or on another host.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Connection failure

If psql reports that it cannot connect, make the target explicit rather than relying on defaults. Check the server is running and accepting connections, then specify -h, -p, -U, and -d as needed. A correct host with the wrong port, or a correct role pointed at the wrong server, produces the same practical outcome: no listing can be returned until a session is established.

Password prompt or authentication failure

A password prompt is normal when the server’s authentication configuration requires one. Enter credentials through the approved PostgreSQL authentication mechanism. If authentication fails, verify the role name, password, host-based authentication rules, and whether the role is permitted to connect to the selected database. Do not place a password directly in the command line or in a script checked into source control.

Names are visible but sizes are blank or unavailable

This is the expected consequence of the documented size-visibility rule for l+. The current role needs CONNECT on the database, superuser status, or membership in pg_read_all_stats to obtain size information. Ask an administrator to grant the least privilege appropriate to the task, or run the check with a role that already has the required visibility.

The SQL query seems to show only one database

Check that you executed the catalog query exactly and did not query a table belonging to the current application database. SELECT datname FROM pg_database; reads the cluster-level catalog and is the appropriate SQL form for listing database names. Also confirm that you are connected to the intended PostgreSQL server; a valid query against a different cluster will still return a correct list, just not the list you expected.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A filtered list is unexpectedly empty

First check whether the pattern belongs to the route you used. The l meta-command uses psql‘s pattern rules, while the SQL example uses a SQL LIKE pattern. When issuing a pattern from a shell, quote it so shell wildcard expansion does not change the text before psql receives it. Then test the unfiltered command to distinguish a pattern mismatch from a connection or visibility problem.

Operational details worth remembering

  • l and list work only at an interactive psql prompt; they are not standalone operating-system commands.
  • psql -l and psql --list are shell options that list databases and then exit.
  • When no target is supplied with -l, psql uses the postgres database for the connection unless you override it with -d or a positional database argument.
  • The catalog query lists databases for the connected cluster, not merely schemas or tables in the current database.
  • Database names, owners, encodings, and privileges are part of the normal l view; sizes, default tablespaces, and descriptions require l+.
  • Size visibility is permission-dependent, so differences between two users’ l+ output can be legitimate.
  • Adding ORDER BY datname to the SQL query makes output deterministic without changing which databases are selected.

Command quick reference

Context Command Result
Interactive psql l Lists databases with names, owners, encodings, and access privileges
Interactive psql list Long spelling of l
Interactive psql l+ Adds database sizes, default tablespaces, and descriptions when visible to the role
Operating-system shell psql -l Lists all available databases, then exits
Operating-system shell psql --list Long spelling of -l
SQL prompt SELECT datname FROM pg_database ORDER BY datname; Returns cluster database names in a stable order

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.