POSTGRESQL
POSTGRESQL 服务与配置
-
确认PostgreSQL服务是否正在运行
$ sudo systemctl status postgresql
-
如果服务未运行,启动它
$ sudo systemctl start postgresql
-
检查 socket 文件是否存在
$ ls /var/run/postgresql/.s.PGSQL.5432
-
默认端口 5432
-
日志
/var/log/postgresql/
-
数据库服务器的认证配置文件
/etc/postgresql/16/main/pg_hba.conf
POSTGRESQL 默认用户
- POSTGRESQL 数据库默认创建管理员账户
postgres
- 安装 POSTGRESQL 会创建一个默认的 LINUX 用户
postgres
Linux 系统默认用户
-
删除用户
postgres
的历史密码$ sudo passwd -d postgres
-
重新设置用户
postgres
的密码└─$ sudo -u postgres passwd New password: Retype new password: passwd: password updated successfully
默认管理员账户
-
登录
POSTGRESQL
$ sudo -u postgres psql -U postgres -p 5432
-
修改管理员账户
postgres
的密码postgres=# alter user postgres with password 'password'; ALTER ROLE postgres=#
创建 DATABASE
-
连接
$ psql postgres psql: error: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: FATAL: role "kali" does not exist
-
切换用户连接数据库 : 将当前用户
kali
切换为postgres
$ sudo -s -u postgres kali% psql postgres WARNING: database "postgres" has a collation version mismatch DETAIL: The database was created using collation version 2.37, but the operating system provides version 2.38. HINT: Rebuild all objects in this database that use the default collation and run ALTER DATABASE postgres REFRESH COLLATION VERSION, or build PostgreSQL with the right library version. psql (16.3 (Debian 16.3-1+b1)) Type "help" for help. postgres=# \q kali% exit
-
-
配置文件
$ ps -ef | grep postgresql postgres 764908 1 0 22:05 ? 00:00:00 /usr/lib/postgresql/16/bin/postgres -D /var/lib/postgresql/16/main -c config_file=/etc/postgresql/16/main/postgresql.conf
-
创建数据库
postgres=# create database rustwebdev; ERROR: template database "template1" has a collation version mismatch DETAIL: The template database was created using collation version 2.37, but the operating system provides version 2.38. HINT: Rebuild all objects in the template database that use the default collation and run ALTER DATABASE template1 REFRESH COLLATION VERSION, or build PostgreSQL with the right library version.
-
数据库
template1
使用的排序规则版本是2.37
, 但操作系统提供2.38
. 因此版本不匹配 . 方案如下.$ sudo -u postgres psql -U postgres -d template1 [sudo] password for kali: WARNING: database "template1" has a collation version mismatch DETAIL: The database was created using collation version 2.37, but the operating system provides version 2.38. HINT: Rebuild all objects
-