1、更新包存储库:
sudo apt update
2、安装Postgresql:
sudo apt install postgresql
3、启动 PostgreSQL服务:
sudo service postgresql start
4、如果本身是 root 用户:
su - postgres
psql
如果是普通用户:
sudo -u postgres psql
5、设置密码:
su - postgres
psql
ALTER USER 数据库名称(一般默认为:postgres) WITH PASSWORD 'xxxx';
6、创建数据库名称:
在psql下:
createdb xxx
7、退出PostgreSQL命令行:
\q
8、退出 “xxx” 用户:
exit
9、如果出现这样的错误:perl: warning: Falling back to the standard locale ("C"). psql: error: FATAL: no pg_hba.conf entry for host "172.17.100.200", user "postgres", database "xxxx", SSL encryption
(1)打开 PostgreSQL 的 pg_hba.conf
文件
sudo nano /etc/postgresql/{version}/main/pg_hba.conf
(2)在文件中添加一行
host dimension postgres 172.17.100.200/32 md5
(3)重启服务
sudo service postgresql restart
10、可以通过命令启动数据库
psql -h localhost -p 5432 -U 你的用户名称 -d 你的数据库名称
11、PostgreSQL开机自启
sudo systemctl enable postgresql.service