PostgreSQL common SQL, pgsql

Source: Internet
Author: User

PostgreSQL common SQL, pgsql

1. view the current database connection

SELECT pg_stat_get_backend_pid(s.backendid) AS procpid,       pg_stat_get_backend_activity(s.backendid) AS current_query    FROM (SELECT pg_stat_get_backend_idset() AS backendid) AS s;

2. view the currently running SQL

SELECT    procpid,    start,    now() - start AS lap,    current_queryFROM    (SELECT        backendid,        pg_stat_get_backend_pid(S.backendid) AS procpid,        pg_stat_get_backend_activity_start(S.backendid) AS start,        pg_stat_get_backend_activity(S.backendid) AS current_query    FROM        (SELECT pg_stat_get_backend_idset() AS backendid) AS S    ) AS SWHERE   current_query <> '<IDLE>'ORDER BY   lap DESC;

3. view the field name of a specified table

    SELECT col_description(a.attrelid,a.attnum) as comment,format_type(a.atttypid,a.atttypmod) as type,a.attname as name, a.attnotnull as notnull    FROM pg_class as c,pg_attribute as a    where c.relname = 'tablename' and a.attrelid = c.oid and a.attnum>0;


4. Multiple like Modes

WHERE somecolumn ~~* any(array['%some%', '%someelse']));

5. delete a connection

 select pg_terminate_backend(pid)               from pg_stat_activity              where pid == pid_number


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.