FAQ

1、根据中文拼音排序

select * from t order by convert_to(name,'GBK') DESC;

2、根据IP来排序,postgresql本身就有IP类型,排序只需要转成IP类型排序即可。

SELECT * FROM t order by CAST(ip as inet) desc;

3、数据库的备份与恢复

#备份

/usr/pgsql-9.5/bin/pg_dump -h 192.168.90.215 -U postgres ivycloud_clouddoc      >/opt/bak/ivycloud_clouddoc.bak

#恢复

/usr/pgsql-9.4/bin/psql -h 192.168.90.205 -U postgres ivycloud_clouddoc < /home/ivycloud_clouddoc.bak

4、删除存在回话的数据库

SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE pid <> pg_backend_pid();

5、创建数据库时报错,错误如下:

ERROR:  source database "template1" is being accessed by other users

DETAIL:  There is 1 other session using the database.

解决方式(暴力解决):

查询出连接该数据库的进程,并将其杀死。

select pg_terminate_backend(pid) from pg_stat_activity where DATNAME = 'template1';


6、shell脚本执行创建数据库失败,命令:sudo -u postgres /opt/pgsql/bin/createdb -O postgres

解决方式:

sed -i -e 's/Defaults    requiretty.*/ #Defaults    requiretty/g' /etc/sudoers

你可能感兴趣的:(FAQ)