1.登录 sudo -u postgres psql 2.查看数据库 \l 3.切换到目标数据库 \c database_name 4.执行sql \i /home/zxx/桌面/database_name.sql 或者在bash命令行直接: psql -U username dbname < dbexport.sql # 例 sudo psql -U...
XanderCheung
8494
0
0
1.登录 sudo -u postgres psql 2.查看数据库 \l 3.切换到目标数据库 \c database_name 4.执行sql \i /home/zxx/桌面/database_name.sql 或者在bash命令行直接: psql -U username dbname < dbexport.sql # 例 sudo psql -U...
XanderCheung
8494
0
0
使用下面的apt命令安装PostgreSQL数据库。sudo apt install postgresql postgresql-contrib libpq-dev -y完成所有安装后,启动Postgres服务并使其在系统引导时每次启动。systemctl start postgresql systemctl enable...
XanderCheung
6317
0
1
查找数据库中各种对象的大小这将以原始字节和“漂亮”形式报告所有表的大小信息。SELECT *, pg_size_pretty(total_bytes) AS total , pg_size_pretty(index_bytes) AS INDEX , pg_size_pretty(toast_bytes) AS...
XanderCheung
7868
0
1
CREATE TABLE AS - 根据查询结果定义新表(完全复制表)CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } | UNLOGGED ] TABLE table_name [ (column_name [, ...] ) ] [ WITH ( storage_parameter [= value] [, ... ] ) | WITH OIDS |...
XanderCheung
6165
0
0
有用的PostgreSQL查询和命令--显示正在运行的查询(9.2之前)-- show running queries (pre 9.2) SELECT procpid, age(clock_timestamp(), query_start), usename, current_query FROM pg_stat_activity WHERE current_query != '<...
XanderCheung
6574
0
0
postgres删除表数据后,并没有释放磁盘空间, 可以用VACUUM 来释放磁盘VACUUM - 垃圾收集并可选地分析数据库话不多说, 如果不想往下看,选择数据库后, 执行:VACUUM full table_name;概要VACUUM [ ( { ...
XanderCheung
47430
1
0
清空表并保留表结构一般情况下,我们使用delete删除表中数据,但是delete是一条数据一条数据来删除表中的数据,直至表清空(保留表结构),但是当数据量很大时,它耗时较久。其...
XanderCheung
8960
2
2
--将远程主机上的数据库备份(转储)到文件-- Dump database on remote host to file $ pg_dump -U username -h hostname databasename > dump.sql --将转储导入现有数据库-- Import dump into existing database $ psql -U usern...
XanderCheung
6155
0
0
SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname='数据库名' AND pid<>pg_backend_pid();
XanderCheung
9135
0
0
Let’s say we have to query a user table with a metadata JSONB column on a PostgreSQL 9.5+ database. 1. Select items by the value of a first level attribute (#1 way) You can query with the @> operator on metadata. This operator can compare...
XanderCheung
4749
0
0
使用此查询查看数据目录 SHOW data_directory; 输出: data_directory ------------------------- /usr/local/var/postgres (1 row) 或者使用以下查询查看 SELECT name, setting FROM pg_settings WHERE category = 'File Lo...
XanderCheung
6658
0
1
例如查看 表 users 中 email 列每一条记录占用空间大小: SELECT pg_size_pretty(pg_column_size("email")::bigint) FROM users; 表 users 中 email 列占用空间总和: SELECT pg_size_pretty(sum(pg_column_size("email")::bigint...
XanderCheung
6398
0
0
Postgresql generate_series 生成数据方法 generate_series 介绍 generate_series ( start integer, stop integer [, step integer ] ) → setof integer generate_series ( start bigint, stop bigint [, step bigint ] ) → setof bigint gene...
XanderCheung
4384
0
0
Let's create test tablemasterwith two columns,con_idwith unique constraint andind_idindexed by unique index. create table master ( con_id integer unique, ind_id integer ); create unique index master_unique_idx on master (ind_id); ...
XanderCheung
4991
0
0