PostgreSQL操作随记:修订间差异

来自三线的随记
无编辑摘要
无编辑摘要
第1行: 第1行:
__TOC__
__TOC__


PostgreSQL默认用户:  postgres
PostgreSQL默认用户:  postgres
第35行: 第34行:
SELECT * FROM pg_stat_activity
SELECT * FROM pg_stat_activity
<br />
<br />


keywords: PSQLException: FATAL: sorry, too many clients already
keywords: PSQLException: FATAL: sorry, too many clients already
第64行: 第62行:
   public | applications        | table | postgres | 8192 bytes |
   public | applications        | table | postgres | 8192 bytes |
  (30 rows)
  (30 rows)
==== enabling expanded  display (like mysql \G) ====
# \x
Expanded display is on.
# \x
Expanded display is off.
run this for a single command by using the <code>\x\g\x</code> suffix to toggle expanded display on, run the query, then toggle it off again.
select * from foo \x\g\x
[[分类:Linux]]
[[分类:Linux]]
__无新段落链接__
__无新段落链接__
__无编辑段落__
__无编辑段落__

2022年5月30日 (一) 17:55的版本

PostgreSQL默认用户: postgres

Connect

psql -h host -U user -W

连接数相关

配置文件

sed  "s/max_connections = .*/max_connections = 1024/" /var/lib/postgresql/data/postgresql.conf|grep max_connection
sed -i "s/max_connections = .*/max_connections = 1024/" /var/lib/postgresql/data/postgresql.conf|grep max_connection

commands

临时修改连接数(待验证)

alter system set max_connections=1024

查看连接数

select count(1) from pg_stat_activity;

查看最大连接数值

show max_connections;

查看保留连接数

show superuser_reserved_connections;

查看连接的客户端信息

SELECT * FROM pg_stat_activity

keywords: PSQLException: FATAL: sorry, too many clients already

common commands

show databases in psql

SELECT datname FROM pg_database;

desc table in psql

postgres=# \c keel
You are now connected to database "keel" as user "postgres".
keel=# \dt
                List of relations
 Schema |         Name         | Type  |  Owner
--------+----------------------+-------+----------
 public | app_permissions      | table | postgres
 public | app_versions         | table | postgres
 public | applications         | table | postgres
(30 rows)

keel=# \dt+
                              List of relations
 Schema |         Name         | Type  |  Owner   |    Size    | Description
--------+----------------------+-------+----------+------------+-------------
 public | app_permissions      | table | postgres | 8192 bytes |
 public | app_versions         | table | postgres | 72 kB      |
 public | applications         | table | postgres | 8192 bytes |
(30 rows)

enabling expanded display (like mysql \G)

# \x
Expanded display is on.
# \x
Expanded display is off.

run this for a single command by using the \x\g\x suffix to toggle expanded display on, run the query, then toggle it off again.

select * from foo \x\g\x