加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

postgresql学习

发布时间:2020-12-13 18:18:54 所属栏目:百科 来源:网络整理
导读:如何查询数据库表的大小 playstore_log= select pg_size_pretty(pg_relation_size('playstore_logs_browse')); pg_size_pretty ---------------- 15 GB (1 row) 查询数据库的大小 playstore_log= select pg_size_pretty(pg_database_size('playstore_log'));

如何查询数据库表的大小
playstore_log=> select pg_size_pretty(pg_relation_size('playstore_logs_browse'));
pg_size_pretty
----------------
15 GB
(1 row)

查询数据库的大小
playstore_log=> select pg_size_pretty(pg_database_size('playstore_log'));
pg_size_pretty
----------------
26 GB
(1 row)

查询表
dt

执行sql脚本
su - postges
cat agent.sql|psql -p1921 agent


遇到的问题

[root@localhost ~]# su - postgres
[postgres@localhost ~]$ psql -p 1921 -U base
Welcome to psql 8.1.23 (server 9.0.2),the PostgreSQL interactive terminal.

Type: copyright for distribution terms
h for help with SQL commands
? for help with psql commands
g or terminate with semicolon to execute query
q to quit

WARNING: You are connected to a server with major version 9.0,
but your psql client is major version 8.1. Some backslash commands,
such as d,might not work properly.

base=> dt ----------------查询表
List of relations
Schema | Name | Type | Owner
--------+-------------------------+-------+----------
public | sys_author | table | postgres
public | sys_district | table | postgres
public | sys_function | table | postgres

base=> d sys_author-------查询表结构,报错了。
ERROR: column "reltriggers" does not exist at character 41
LINE 1: SELECT relhasindex,relkind,relchecks,reltriggers,relhasr...

原因分析:

正常情况是不会出现表结构不能查询的。

Welcome to psql 8.1.23 (server 9.0.2),the PostgreSQL interactive terminal.

大家可以看到,psql命令是8.1版本的,postgresql服务是9.0版本的,所以这个原因就是版本不兼容导致的。

所以要用与postgresql服务对应的psql命令登录才能查询成功。

[root@localhost ~]# /data/soft/pgsql/bin/psql -p 1921 -U postgres android_base------以postgres身份登录android_base库

psql (9.0.2)
Type "help" for help.

android_base=# dt
List of relations
Schema | Name | Type | Owner
--------+------------+-------+----------
public | tbl_locale | table | postgres
public | tbl_lookup | table | postgres
(2 rows)

android_base=# d tbl_lookup
Table "public.tbl_lookup"
Column | Type | Modifiers
-------------+-----------------------------+---------------------------------
id | bigint | not null
create_time | timestamp(6) with time zone |
value | character varying(100) | default NULL::character varying
key | character varying(100) | default NULL::character varying
type | character varying(100) | default NULL::character varying
Indexes:
"tbl_lookup_pkey" PRIMARY KEY,btree (id)

查询成功。


未完待续

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读