postgresDB

Posted tao-yuan

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了postgresDB相关的知识,希望对你有一定的参考价值。

https://blog.csdn.net/u014698745/article/details/86612511

1、pg_hba.conf配置PostgreSQL数据库的访问权限。

找到“# IPv4 local connections:“后,回车另起一行,添加参数行如下,保存即可。
host ? ?all ? ? ? ? ? ? all ? ? ? ? ? ? 0.0.0.0/0 ? ? ? ? ? ??? ?trust

如图所示
————————————————
版权声明:本文为CSDN博主「trycache」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/u014698745/article/details/86612511
技术图片

2、postgresql.conf配置PostgreSQL数据库服务器的相应的参数。

找到“listen_addresses“参数后,设置listen_addresses = ‘*‘,保存即可。

3.重启postgresDB

重用命令

在windows的dos窗口连接数据库, 默认的用户和数据库是postgres
psql -U user -d dbname

切换数据库,相当于mysql的use dbname
\\c dbname
列举数据库,相当于mysql的show databases
\\l
列举表,相当于mysql的show tables
\\dt
查看表结构,相当于desc tblname,show columns from tbname
\\d tblname

\\di 查看索引

创建数据库:
create database [数据库名];
删除数据库:
drop database [数据库名];
重命名一个表:
alter table [表名A] rename to [表名B];
删除一个表:
drop table [表名];

*在已有的表里添加字段:
alter table [表名] add column [字段名] [类型];

删除表中的字段:

alter table [表名] drop column [字段名];

修改数据库列属性

alter table 表名 alter 列名 type 类型名(350)

重命名一个字段:
alter table [表名] rename column [字段名A] to [字段名B];
给一个字段设置缺省值:
alter table [表名] alter column [字段名] set default [新的默认值];
去除缺省值:
alter table [表名] alter column [字段名] drop default;
在表中插入数据:
insert into 表名 ([字段名m],[字段名n],......) values ([列m的值],[列n的值],......);
修改表中的某行某列的数据:
update [表名] set [目标字段名]=[目标值] where [该行特征];
删除表中某行数据:
delete from [表名] where [该行特征];
delete from [表名];--删空整个表
创建表:
create table ([字段名1] [类型1] ;,[字段名2] [类型2],......<,primary key (字段名m,字段名n,...)>;);

\\copyright 显示 PostgreSQL 的使用和发行条款
\\encoding [字元编码名称]
显示或设定用户端字元编码
\\h [名称] SQL 命令语法上的说明,用 * 显示全部命令
\\prompt [文本] 名称
提示用户设定内部变数
\\password [USERNAME]
securely change the password for a user
\\q 退出 psql

可以使用pg_dump和pg_dumpall来完成。比如备份sales数据库:
pg_dump drupal>/opt/Postgresql/backup/1.bak

以上是关于postgresDB的主要内容,如果未能解决你的问题,请参考以下文章