pid,
datname,
usename,
client_addr,
application_name,
STATE,
backend_start,
xact_start,
xact_stay,
query_start,
query_stay,
REPLACE ( query, chr( 10 ), ‘ ‘ ) AS query
FROM
(
SELECT
pgsa.pid AS pid,
pgsa.datname AS datname,
pgsa.usename AS usename,
pgsa.client_addr client_addr,
pgsa.application_name AS application_name,
pgsa.STATE AS STATE,
pgsa.backend_start AS backend_start,
pgsa.xact_start AS xact_start,
EXTRACT ( epoch FROM ( now( ) – pgsa.xact_start ) ) AS xact_stay,
pgsa.query_start AS query_start,
EXTRACT ( epoch FROM ( now( ) – pgsa.query_start ) ) AS query_stay,
pgsa.query AS query
FROM
pg_stat_activity AS pgsa
WHERE
pgsa.STATE !=’idle’
AND pgsa.STATE !=’idle in transaction’
AND pgsa.STATE !=’idle in transaction (aborted)’
) idleconnections
ORDER BY
query_stay DESC
字段解释PID数据库查询进程IDquery_stay查询时长秒query查询SQL语句
SELECT pg_terminate_backend(6289);
修改track_activity_query_size的值重启数据库服务
touch insert_sql.sh
. /etc/profile
. ~/.bash_profile
export PATH=/usr/pgsql-12/bin:/usr/bin;
export PGPASSWORD=数据库密码;psql -U postgres -d 数据库名称 < /mnt/nas/bak-06/1.sql;
指定postgres用户执行导入某个表的语句,免密执行shell脚本touch nasen_insert.sql
source /etc/profile
PATH=/usr/local/bin:$PATH
echo ‘task_start’
runuser – postgres -g postgres -c “sh /data/test/insert_sql.sh”
echo ‘task_finish’
定时器配置
touch drop01.sql
#删除某个表SQL语句
DROP TABLE IF EXISTS public.test;
touch drop.sh
. /etc/profile
. ~/.bash_profile
export PATH=/usr/pgsql-12/bin:/usr/bin;
#su postgres
export PGPASSWORD=123456;psql -U postgres -d 数据库名称 < /data/test/drop01.sql;
touch nasen_drop.sh
source /etc/profile
PATH=/usr/local/bin:$PATH
echo ‘task_start’
runuser – postgres -g postgres -c “sh /data/test/drop.sh”
echo ‘task_finish’
定时器调用
备份导出整个数据库
导入某个数据库
步骤1:创建新data目录
步骤2:关闭数据库服务
步骤3:执行复制
步骤4:修改服务配置文件
步骤5:重新加载服务配置
步骤6:重启数据库服务
步骤7:查看变更状态
步骤1:安装postgis的依赖包
步骤2:安装postgis
步骤3:安装完毕后切换为postgres用户,开启扩展初始化操作
// 开启插件
# psql
// 开启pgsql的插件
postgres=# create extension postgis;
postgres=# create extension postgis_topology;
postgres=# create extension fuzzystrmatch;
postgres=# create extension address_standardizer;
postgres=# create extension address_standardizer_data_us;
postgres=# create extension postgis_tiger_geocoder;
//查看版本,验证安装是否成功
postgres=# SELECT PostGIS_full_version();
步骤4:安装pgRouting
步骤5:检查插件是否完成
postgres=# create extension “uuid-ossp”;
ERROR: could not open extension control file “/opt/pgsql12.2/share/extension/uuid-ossp.control”: No such file or directory
步骤1:安装uuid依赖包
## 步骤2:执行编译配置
[root@Location-01 postgresql-12.2]# pwd
/usr/local/src/postgresql-12.2
[root@Location-01 postgresql-12.2]# https://www.jb51.net/article/configure –prefix=/opt/pgsql12.2 –with-uuid=ossp
步骤3:编译安装uuid-ossp
[root@Location-01 uuid-ossp]# pwd
/usr/local/src/postgresql-12.2/contrib/uuid-ossp
[root@Location-01 uuid-ossp]# make && make install
步骤4:检测是否成功
CREATE EXTENSION
name | default_version | installed_version | comment
————+—————–+——————-+————————————————-
plpgsql | 1.0 | 1.0 | PL/pgSQL procedural language
plperl | 1.0 | | PL/Perl procedural language
plperlu | 1.0 | | PL/PerlU untrusted procedural language
plpython2u | 1.0 | | PL/Python2U untrusted procedural language
plpythonu | 1.0 | | PL/PythonU untrusted procedural language
uuid-ossp | 1.1 | | generate universally unique identifiers (UUIDs)
(6 rows)
到此这篇关于PostgreSQL实时查看数据库实例正在执行的SQL语句的文章就介绍到这了,更多相关PostgreSQL查看正在执行SQL语句 内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!