Linux/Postgres: Difference between revisions
< Linux
mNo edit summary |
mNo edit summary |
||
Line 102: | Line 102: | ||
|} | |} | ||
== List all databases | == Databases == | ||
* List all databases | |||
<blockquote> | <blockquote> | ||
<pre> | <pre> | ||
Line 110: | Line 111: | ||
</blockquote> | </blockquote> | ||
== List all tables | == Tables == | ||
* List all tables | |||
<blockquote> | <blockquote> | ||
<pre> | <pre> | ||
Line 116: | Line 118: | ||
WHERE table_type = 'BASE TABLE' AND table_schema = 'public' | WHERE table_type = 'BASE TABLE' AND table_schema = 'public' | ||
ORDER BY table_type, table_name | ORDER BY table_type, table_name | ||
</pre> | |||
</blockquote> | |||
* Biggest tables by size | |||
<blockquote> | |||
<pre> | |||
SELECT | |||
nspname || '.' || relname AS "Object Name", relkind As "Object Type", | |||
pg_size_pretty(pg_relation_size(C.oid)) AS "size" | |||
FROM pg_class C | |||
LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace) | |||
WHERE nspname NOT IN ('pg_catalog', 'information_schema') | |||
ORDER BY pg_relation_size(C.oid) DESC | |||
LIMIT 20; | |||
</pre> | </pre> | ||
</blockquote> | </blockquote> |
Revision as of 19:01, 29 September 2024
Data types
Type | min | max | comment |
---|---|---|---|
boolean | |||
char(n) | |||
varchar(n) | |||
text | |||
smallint | -32768 | 32767 | |
int | |||
serial | (~auto_increment in mysql) | ||
float(n) | |||
real / float8 | |||
numeric(p,s) | |||
date | |||
time | |||
timestamp | |||
timestamptz | |||
interval | |||
json | |||
jsonb | |||
uuid | |||
+ special |
Databases
- List all databases
SELECT datname FROM pg_database WHERE datistemplate = false;
Tables
- List all tables
SELECT table_catalog,table_schema,table_name FROM information_schema.tables WHERE table_type = 'BASE TABLE' AND table_schema = 'public' ORDER BY table_type, table_name
- Biggest tables by size
SELECT nspname || '.' || relname AS "Object Name", relkind As "Object Type", pg_size_pretty(pg_relation_size(C.oid)) AS "size" FROM pg_class C LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace) WHERE nspname NOT IN ('pg_catalog', 'information_schema') ORDER BY pg_relation_size(C.oid) DESC LIMIT 20;
List all users
SELECT * FROM pg_user;