Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

[PG_PSQL] PSQL usage test

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

-- psql function and application-- create user. Role does not have login permission create user mydbuser with encrypted password 'mydbuser';--orcreate role mydbuser with encrypted password' mydbuser';alter role mydbuser with login; by default-- create tablespace mkdir-p / pgdata/10/data/pg_tbs/tbs_mydbcreate tablespace tbs_mydb owner mydbuser location'/ pgdata/10/data/pg_tbs/tbs_mydb';-- create database create database mydb with owner=mydbuser template=template0 encoding='UTF8' tablespace=tbs_mydb -- empower grant all on database mydb to mydbuser with grant option;grant all on tablespace tbs_mydb to mydbuser;-- to view role information\ duSELECT * FROM pg_roles;-- delete role revoke all on database mydb from test;drop role test;-- connection psql mydb mydbuser-- list database information pg_database\ l color-table space list pg_tablespace\ db-- view table information pg_classcreate table test_1 (id int4,name text,create_time timestamp without time zone default clock_timestamp ()) Alter table test_1 add primary key (id);\ d test_1\ dt+ test_1insert into test_1 (id,name) select n | |'_ francs' from generate_series (1m 300000) nmittal insert into test_1 values (100001m (100001m) France') -- Index size\ di+ test_1_pkey-- get meta command psql-E mydb mydbuser-- large amount of data, copy (superuser only) has higher performance than\ copy psql mydb postgrescopy table_copy from'/ home/postgres/test_copy_in.txt';copy table_copy to'/ home/postgres/table_copy_in.txt';--csv format copy table_copy to'/ home/postgres/table_copy_in.csv' with csv header -- A unformatted output,-t displays only data psql-At-c "select oid,relname,relfilenode from pg_class limit 2" mydb mydbuser-- executes relevant script psql mydb mydbuser- f xx.sql-- to view active session select pid,usename,datname,query,client_addr from pg_stat_activity where pidpg_backend_pid () and state='active' order by query -- check the waiting event select pid,usename,datname,query,client_addr,wait_event_type,wait_event from pg_stat_activity where pidpg_backend_pid () and wait_event is not null order by wait_event_type;-- to view the number of database connections select datname,usename,client_addr,count (*) from pg_stat_activity where pidpg_backend_pid group by 1 from pg_stat_activity where pidpg_backend_pid group by 2 order by 1 desc -- Edit .psqlrc\ set active_session 'select pid,usename,datname,query,client_addr from pg_stat_activity where pidpg_backend_pid () and state=\' active\ 'order by query';-- execute: active_session-- execute the current sql\ watch [seconds] repeatedly-- view the current time select now ();-- psql view psql-- help\?

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report