微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

postgresql学习

如何查询数据库表的大小
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)

查询成功。

未完待续

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐