在 Debian 上用 PostgreSQL 创建数据库,一般步骤如下:
sudo apt update
sudo apt install postgresql postgresql-contrib
安装完成后,PostgreSQL 会自动创建一个名为 postgres 的系统用户和数据库超级用户。
sudo -i -u postgres
createdb 命令createdb mydb
其中 mydb 是数据库名。
psql
进入后执行:
CREATE DATABASE mydb;
退出:
\q
createuser --interactive
或
CREATE USER myuser WITH PASSWORD 'mypassword';
GRANT ALL PRIVILEGES ON DATABASE mydb TO myuser;
psql -U myuser -d mydb -h localhost
pg_hba.conf 和 postgresql.confsudo systemctl status postgresql
sudo systemctl start postgresql
如果你需要 指定编码、所有者或远程访问配置,可以告诉我你的使用场景。