| PSQL META Command | Usage |
|---|---|
| \dt | List the table |
| \dn | List the sachems |
| \l | List the databases |
| \di | List of Indexes |
| \d <table-name> | Describe table(Columns and their type) |
| \db | List of table spaces(In which places tables are storing) |
| \du | List of users |
| \ds | List of system table |
| \dvs | List of system views |
| \l+ | List of databases with size |
| \dt+ | List of tables with size |
| \! | present working directory |
| \dp | Table space privileges |
| \q | Quit from psql shell |
| select current_user | To view current user |
How to switch to database/user?
\c <db> <user>
how to create database outside?
createdb -p 5444 <db-name> -u <user>
Note: we can refer for port in postgres.conf
How to write Query results in to file?
\o <path>
select * from <table-name>;
\o --->switching off
How to importing script?
\i <path of .sql file>
How to print time taken by query?
\timing
-->time take to run particular query
Query
\timtig -->turn off
How to write history of commands into file?
\s <path>
Alternate for \dt+
select pg_relation_size('<table-name>')
output in bytes
select pg_size_pretty(pg_relation_size('<table-name>'))
output in MBs or in GB
select pg_size_pretty(pg_database_size('<database-name>'))
output in MBs or in GB
select pid from pg_stat_activity;
above query will prints process id of PostgreSQL
also see below
No comments:
Post a Comment