Postgresql: Difference between revisions
Jump to navigation
Jump to search
(→exit) |
(§) |
||
Line 37: | Line 37: | ||
=Getting help= | =Getting help= | ||
\? or \h | \? or \h | ||
=size of database= | |||
SELECT pg_size_pretty( pg_database_size('database') ); | |||
=size of table= | |||
SELECT pg_size_pretty( pg_total_relation_size('tablename') ); |
Revision as of 08:26, 23 March 2020
psql
Connect to remote database:
export PGPASSWORD=password && psql --host=10.111.222.1 --port=5492 --username=user --no-password postgres
install psql
apt-get install freetds-bin
List databases
1
SELECT datname FROM pg_database;
2
\l
select database
\c testdb;
show tables
\dt
Change view. One line per attribute
\x on
exit/quit
\q
update
UPDATE users SET admin = 1 WHERE user_id = 14002;
Create database
CREATE DATABASE dbname OWNER username;
Delete database
DROP DATABASE dbname;
Import a database
psql username -h hostname -d dbname < dump.sql
Create user
CREATE USER username WITH PASSWORD 'MYPASS';
Set super privileges
ALTER USER username WITH SUPERUSER;
List users
\du
Deleting user
DROP USER nomusr
Getting help
\? or \h
size of database
SELECT pg_size_pretty( pg_database_size('database') );
size of table
SELECT pg_size_pretty( pg_total_relation_size('tablename') );