- Log in PostgreSQL
- Log in postgres
sudo -u postgres psql
- Switching Database
\ C I
- PostgreSQL command
\ C [database_name] : switch databases
\ C - [user_name]: switch user
\ L : List all databases
\ D: List all the current database table
\ D [table_name]: List of a structure of a table
\ Du: List all users
\ Conninfo: Lists the current database and connection information
\ H: View explain SQL commands, such as \ h select
\ ?: View psql command list
\ E: Open a text editor
\ Q: quit
- View PostgreSQL Deadlock
sudo ps -if | grep postgres
Note: If you have a lot of wait instructions database deadlock.
- postgreSql View deadlocks and solutions
- View the process database
SELECT * FROM pg_stat_activity WHERE datname = 'deadlock database ID';
Retrieved field, [wating] field, data t of the piece, is the deadlock of the process, find the [value] procpid corresponding column.
E.g:
SELECT procpid FROM pg_stat_activity WHERE datname='数据库ID' and waiting ='t';
- Kill the process, kill two ways:
The first:
SELECT pg_cancel_backend (PID);
this way only the kill the SELECT query , to update, delete and DML does not take effect)
The second:
SELECT pg_terminate_backend(PID);
This can kill off various operations (select, update, delete, drop, etc.) operation