Postgre SQL   发布时间:2022-05-20  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了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)

查询成功。

未完待续

大佬总结

以上是大佬教程为你收集整理的postgresql学习全部内容,希望文章能够帮你解决postgresql学习所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: