Postgres 10 绿色版(windows)的安装和配置
下载
官网下载地址:https://www.postgresql.org/download/windows/
绿色版本地址:https://www.enterprisedb.com/download-postgresql-binaries
进入绿色版本地址,按照操作系统版本下载
参考文档:
https://www.bbsmax.com/A/E35p4rVE5v/
安装
把软件解压到:d:\work\postgresql-10.23
创建数据目录:d:\work\postgresql-10.23\data
初始化数据库
d:\work\postgresql-10.23\bin\initdb.exe -D d:\work\postgresql-10.23\data -E UTF8
注册windows服务(可选)
d:\work\postgresql-10.23\bin\pg_ctl.exe register -N PostgreSQL -D d:\work\postgresql-10.23\data
-N表示服务名
启动服务
net start PostgreSQL
卸载服务
net stop PostgreSQL
d:\work\postgresql-10.23\bin\pg_ctl.exe unregister -N PostgreSQL
未注册windows服务的启动方式
d:\work\postgresql-10.23\bin\postgres.exe -D d:\work\postgresql-10.23\data
或者:
d:\work\postgresql-10.23\bin\pg_ctl.exe -D d:\work\postgresql-10.23\data -l logfile start
未注册windows服务的关闭方式
d:\work\postgresql-10.23\bin\pg_ctl.exe stop -m fast -D d:\work\postgresql-10.23\data
-m 后可以接三个参数值:smart;fast(默认);immediate
修改PostgresSQL 数据库配置实现远程访问
修改服务配置文件:d:\work\postgresql-10.23\data\postgresql.conf:
将 listen_addresses = ’localhost’ 改成 listen_addresses =’*'
修改客户端认证配置文件:d:\work\postgresql-10.23\data\pg_hba.conf:
将 host all all 127.0.0.1/32 trust 修改成 host all all 0.0.0.0/0 trust
将 host replication all 127.0.0.1/32 trust 修改成 host replication all 0.0.0.0/0 trust
重启postgres服务使配置生效
操作
创建root用户,并设置为超级管理员
d:\work\postgresql-10.23\bin\createuser.exe -P -s -e root
创建test数据库
d:\work\postgresql-10.23\bin\createdb.exe test
给表添加注释:
comment on table ac_menu is ‘菜单表’;
表示为表 ac_menu 添加注释
给列添加注释:
comment on column ac_menu.id is ‘主键ID,自增’;
表示为表 ac_menu 的字段 id 添加注释
注意:创建表的时候,不能再列后面加 comment;添加后执行会报错,这是 MySQL,Oracle的用法,Postgresql 不支持该写法。
进入sql模式:
d:\work\postgresql-10.23\bin\psql.exe postgres
1# d:\work\postgresql-10.23\bin\psql.exe postgres
2psql (10.23)
3输入 "help" 来获取帮助信息.
4
5postgres=# \du
6 角色列表
7 角色名称 | 属性 | 成员属于
8-----------+--------------------------------------------+----------
9 zhangcong | 超级用户, 建立角色, 建立 DB, 复制, 绕过RLS | {}
10
11
12postgres=#
评论