Skip to content

Instantly share code, notes, and snippets.

@cybersamx
Last active August 29, 2015 14:04
Show Gist options
  • Save cybersamx/effbcbab830f0e8d83a1 to your computer and use it in GitHub Desktop.
Save cybersamx/effbcbab830f0e8d83a1 to your computer and use it in GitHub Desktop.
PostgreSQL System Commands
-- List of all databases
\list
-- Connect to database
\c MyDatabase
-- List of tables and relations
\dt
-- Schema of a table
\d MyTable
-- List all schemas
\dn
-- Version of Postgres
select version();
-- Current database
select current database();
-- Current user
select current_user;
-- Postgres start time/uptime
select pg_postmaster_start_time();
-- Size of a databse
select pg_database_size('MyDatabase'); -- Output in bytes
select pg_size_pretty(pg_database_size('MyDatabase')); -- Output in kB, MB, GB, or TB as appropriate.
-- Size of a table
select pg_total_relation_size('MyTable');
-- Postgres IP address
select inet_server_addr();
-- Postgres TCP/IP port
select inet_server_aort();
-- Reference
-- 1. http://www.uptimemadeeasy.com/databases/helpful-postgresql-commands/
-- 2. http://www.postgresql.org/docs/manuals/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment