Legg til kolonne

alter table bord add column bordlengde integer default 5

Legg til fremmednøkkel

alter table gateway add foreign key (editable) references role(id);

add readonly user

$ sudo -u postgres psql database postgres=# CREATE ROLE readonly WITH LOGIN ENCRYPTED PASSWORD '<USE_A_NICE_STRONG_PASSWORD_PLEASE'; postgres=# GRANT SELECT ON ALL TABLES IN SCHEMA public TO readonly;

Find locks tied to table

select * from pg_locks where relation=(select oid from pg_class where relname='');

Cancel or kill transactions

Or find the underlying problem!

select pg_cancel_backend()

select pg_terminate_backend()

Active and idle querys

select * from pg_stat_activity where state = 'active';

select * from pg_stat_activity where state ~* 'idle'; -- regex!

List enums in database


Settings override

SELECT name, current_setting(name), source, sourcefile, sourceline FROM pg_settings WHERE (source <> 'default' OR name = 'server_version') AND name NOT IN ('config_file', 'data_directory', 'hba_file', 'ident_file');