PostgreSQL Basics

  1. Log in PostgreSQL
  1. Log in postgres

sudo -u postgres psql

  1. Switching Database

\ C I

  1. 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

  1. View PostgreSQL Deadlock

sudo ps -if | grep postgres

 

Note: If you have a lot of wait instructions database deadlock.

  1. postgreSql View deadlocks and solutions
  1. 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';

  1. 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

 

Guess you like

Origin blog.csdn.net/sa19861211/article/details/91574181