Domanda

How do I list all extensions that are already installed in a database or schema from psql?

See also

È stato utile?

Soluzione

In psql that would be

\dx

See the manual of psql for details.

Doing it in plain SQL it would be a select on pg_extension:

SELECT * 
FROM pg_extension;

Altri suggerimenti

Additionally if you want to know which extensions are available on your server: SELECT * FROM pg_available_extensions.

See pg_available_extensions and pg_available_extension_versions.

This SQL query gives output similar to \dx:

SELECT e.extname AS "Name", e.extversion AS "Version", n.nspname AS "Schema", c.description AS "Description" 
FROM pg_catalog.pg_extension e 
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = e.extnamespace 
LEFT JOIN pg_catalog.pg_description c ON c.objoid = e.oid AND c.classoid = 'pg_catalog.pg_extension'::pg_catalog.regclass 
ORDER BY 1;

Thanks to https://blog.dbi-services.com/listing-the-extensions-available-in-postgresql/

Just a comment that whether you run as suggested above, in psql either

\dx

or

select extname from pg_extension ;

Keep in mind that

  1. Make sure you are connected to the right database. As your extensions are loaded database specific.
  2. Any extensions added to template1 database will by definition, appear on all databases.

Before pulling the extension info, a bit of what's running in the background as this can be helpful if you are using query directly from an app or driver to pull this info from postgresql. \dx is pulling info for you from a combination of catalogs called pg_extension, pg_namespace, pg_description and regclass.

Log in, into the psql prompt mentioned below:

psql -h localhost -d postgres -U username -E

with an -E switch which gives you the details of the hidden commands that any alias is using. Once you are IN you can simply do a \dx

which gives you this:

********* QUERY **********
SELECT e.extname AS "Name", e.extversion AS "Version", n.nspname AS 
"Schema", c.description AS "Description"
FROM pg_catalog.pg_extension e 
LEFT JOIN pg_catalog.pg_namespace n 
ON n.oid = e.extnamespace 
LEFT JOIN pg_catalog.pg_description c 
ON c.objoid = e.oid AND c.classoid = 
'pg_catalog.pg_extension'::pg_catalog.regclass
ORDER BY 1;
**************************

                 List of installed extensions
  Name   | Version |   Schema   |         Description
---------+---------+------------+------------------------------
 plpgsql | 1.0     | pg_catalog | PL/pgSQL procedural language

If you were to use a client like DBweaver or PGADMIN, then the slash command might not work for you or even in case of ORM's etc. That's where you can use the above and get similar info on extension or even any other alias commands of postgres.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top