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)
查询成功。
未完待续
本文出自 “秋风颂” 博客,请务必保留此出处http://qiufengsong.blog.51cto.com/7520243/1386882
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。