Benutzer-Werkzeuge

Webseiten-Werkzeuge


commands-postgresql

Sammlung nützlicher Befehle

PostgreSQL Commands

dump all databases to a compressed file and restore

su -l postgres -c pg_dumpall | xz > ~/db_`date +%Y-%m-%d:%H:%M:%S`.sql.xz
xzcat pg_dumpall.YOURTIMESTAMP.sql.xz | su -l postgres -c 'psql -f -'

cleanup disk space

psql -U postgres -d nameofyourdatabase -c 'VACUUM FULL;'

list all users

psql -U postgres -c 'SELECT * FROM pg_user;'

some information about the user

SELECT CURRENT_USER;
SELECT * FROM information_schema.role_table_grants WHERE grantee='myexampleuser';

set password for a user

ALTER USER theusername WITH ENCRYPTED PASSWORD 'thepassword';

shortcuts

---- list all databases
\l
---- ...with more details
\l+
---- list users
\du
---- connect to database
\c my_db_name
---- list tables of connected database
\dt
---- ...with more details
\d+
---- list columns of a table
\d+ my_table_name
---- list extensions
\dx
---- list current connections
SELECT * FROM pg_stat_activity;
---- show version information
SELECT version();
Cookies helfen bei der Bereitstellung von Inhalten. Durch die Nutzung dieser Seiten erklären Sie sich damit einverstanden, dass Cookies auf Ihrem Rechner gespeichert werden. Weitere Information
commands-postgresql.txt · Zuletzt geändert: 2019/11/08 13:49 von alex