在Debian上安裝PostgreSQL數據庫的步驟如下:
更新APT包列表
sudo apt update
安裝PostgreSQL服務器
sudo apt install postgresql
啟動并啟用PostgreSQL服務
sudo systemctl start postgresql
sudo systemctl enable postgresql
檢查PostgreSQL服務狀態
sudo systemctl status postgresql
切換到postgres用戶并設置密碼
sudo -u postgres psql
在psql命令行中,執行以下SQL命令來設置或更改postgres用戶的密碼:
ALTER USER postgres WITH PASSWORD 'your_password';
創建新數據庫和用戶(可選) 你可以在psql命令行中創建新的數據庫和用戶:
CREATE DATABASE mydatabase;
CREATE USER myuser WITH ENCRYPTED PASSWORD 'mypassword';
GRANT ALL PRIVILEGES ON DATABASE mydatabase TO myuser;
退出psql命令行
\q
添加Debian官方PostgreSQL倉庫 創建一個新的APT倉庫文件:
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
導入倉庫GPG密鑰
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
更新APT包列表
sudo apt update
安裝PostgreSQL服務器
sudo apt install postgresql-13
啟動并啟用PostgreSQL服務
sudo systemctl start postgresql
sudo systemctl enable postgresql
檢查PostgreSQL服務狀態
sudo systemctl status postgresql
切換到postgres用戶并設置密碼
sudo -u postgres psql
在psql命令行中,執行以下SQL命令來設置或更改postgres用戶的密碼:
ALTER USER postgres WITH PASSWORD 'your_password';
創建新數據庫和用戶(可選) 你可以在psql命令行中創建新的數據庫和用戶:
CREATE DATABASE mydatabase;
CREATE USER myuser WITH ENCRYPTED PASSWORD 'mypassword';
GRANT ALL PRIVILEGES ON DATABASE mydatabase TO myuser;
退出psql命令行
\q
postgresql-13、postgresql-14等)。通過以上步驟,你應該能夠在Debian上成功安裝并配置PostgreSQL數據庫。