How to get primary key of a table from PostgreSQL

by

SELECT
pg_attribute.attname,
format_type(pg_attribute.atttypid, pg_attribute.atttypmod)
FROM pg_index, pg_class, pg_attribute, pg_namespace
WHERE
pg_class.oid = 'my_table_name'::regclass AND
indrelid = pg_class.oid AND
nspname = 'my_schema_name' AND
pg_class.relnamespace = pg_namespace.oid AND
pg_attribute.attrelid = pg_class.oid AND
pg_attribute.attnum = any(pg_index.indkey)
AND indisprimary

See official version: http://wiki.postgresql.org/wiki/Retrieve_primary_key_columns

See also:

How to get primary key of a table from SQLite

How to get primary key of a table from MySQL

How to get primary key of a table from SQL Server

How to get primary key of a table from DB2

How to get primary key of a table from Oracle

Some PostgreSQL tools you can try: https://www.withdata.com/postgresql/