0

ubuntu 安装 Postgres

 1 year ago
source link: https://www.jansora.com/notebook/107602
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

March 27th 2023, 3:57:23 pm


Model: GPT-4

ubuntu 安装 postgresql 9.6

Question :

ubuntu 安装 postgresql 9.6

Answer :

在 Ubuntu 上安装 PostgreSQL 9.6 需要遵循以下步骤。但请注意,PostgreSQL 9.6 的支持可能已经终止,建议您安装更新的版本。如果您确实需要安装 PostgreSQL 9.6,请按照以下步骤操作:

  1. 添加 PostgreSQL 官方仓库:

首先,导入 PostgreSQL 官方仓库的公钥:

wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -

然后,创建一个新的 Apt 源列表文件,以便将 PostgreSQL 官方仓库添加到您的系统中:

echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main" | sudo tee /etc/apt/sources.list.d/pgdg.list
  1. 更新软件包列表并安装 PostgreSQL 9.6:

现在,更新您的软件包列表:

sudo apt update

接着,安装 PostgreSQL 9.6:

sudo apt install postgresql-9.6
  1. 启动并启用 PostgreSQL 服务:

启动 PostgreSQL 服务:

sudo systemctl start postgresql

设置 PostgreSQL 服务在启动时自动启动:

sudo systemctl enable postgresql
  1. 验证安装:

安装完成后,您可以使用以下命令检查 PostgreSQL 服务的状态:

sudo systemctl status postgresql

postgresql 9.6 配置开机启动

Question :

postgresql 9.6 配置远程访问

Answer :

为了在 Ubuntu 上配置 PostgreSQL 9.6 进行远程访问,请按照以下步骤操作:

  1. 修改 postgresql.conf 文件:

首先,找到并打开 postgresql.conf 文件。它通常位于 /etc/postgresql/9.6/main 目录下。使用文本编辑器打开它,例如使用 nano 编辑器:

sudo nano /etc/postgresql/9.6/main/postgresql.conf

找到以下行:

#listen_addresses = 'localhost'

取消注释并将其更改为:

listen_addresses = '*'

保存并关闭文件。

  1. 修改 pg_hba.conf 文件:

接下来,找到并打开 pg_hba.conf 文件。它通常位于 /etc/postgresql/9.6/main 目录下。使用文本编辑器打开它:

sudo nano /etc/postgresql/9.6/main/pg_hba.conf

在文件末尾添加以下行,以允许所有 IP 地址访问所有数据库并使用密码认证:

host    all             all             0.0.0.0/0            md5
host    all             all             ::/0                 md5

如果您只想允许特定 IP 地址或范围访问,请将 0.0.0.0/0 和 ::/0 替换为所需的 CIDR 地址。保存

postgresql 9.6 配置远程访问 修改密码

Question :

postgresql 9.6 配置远程访问 修改密码

Answer :

要修改 PostgreSQL 9.6 用户(如 postgres 用户)的密码以进行远程访问,请按照以下步骤操作:

  1. 切换到 postgres 用户:
sudo -u postgres -i
  1. 启动 PostgreSQL 命令行客户端 psql:
psql
  1. 修改 postgres 用户的密码。将 your_new_password 替换为您选择的新密码:
ALTER USER postgres WITH PASSWORD 'your_new_password';
  1. 输入 \q 退出 psql 命令行客户端:
\q
  1. 退出 postgres 用户:
exit

现在,您已成功更改了 postgres 用户的密码。要进行远程访问,请确保您已按照之前的回答正确配置了远程访问。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK