root@ykla:~ # /usr/local/etc/rc.d/postgresql initdbThe files belonging to this databasesystem will be owned by user "postgres".This user must also own the server process.The database cluster will be initialized with localesCOLLATE: C CTYPE: C.UTF-8 MESSAGES: C.UTF-8 MONETARY: C.UTF-8NUMERIC: C.UTF-8TIME: C.UTF-8The defaulttext search configuration will be setto"english".Datapage checksums are disabled.creating directory /var/db/postgres/data96 ... okcreating subdirectories ... okselecting default max_connections ... 100selecting default shared_buffers ... 128MBselecting default timezone ... PRCselecting dynamic shared memory implementation ... posixcreating configuration files ... okrunning bootstrap script ... okperforming post-bootstrap initialization ... oksyncing datatodisk ... okWARNING: enabling "trust"authenticationforlocal connectionsYou can change this by editing pg_hba.conf orusing the option-A, or--auth-local and --auth-host, the next time you run initdb.Success. You can nowstart the databaseserverusing:/usr/local/bin/pg_ctl -D /var/db/postgres/data96 -l logfile startroot@ykla:~ #
登录使用
Postgresql 默认是没有 root 用户的,需要使用其创建的 postgres 用户登录。
示例输出:
root@ykla:~ # psqlpsql: FATAL: role"root" does not exist
正确用法:
#切换用户root@ykla:~ # su - postgres#启动服务$ /usr/local/bin/pg_ctl -D /var/db/postgres/data96 -l logfile start#创建新用户 ykla,并设置密码$ createuser -sdrP yklaEnter passwordfor new role:Enter it again:$#创建数据库$ createdb new_db#登录进数据库并将数据库权限赋予用户 ykla。$ psqlpsql (9.6.24)Type"help"for help.postgres=# ALTER USER ykla WITHENCRYPTEDPASSWORD'password';ALTERROLEpostgres=#postgres=# GRANT ALL PRIVILEGES ONDATABASE new_db TO ykla;GRANT#退出数据库postgres=# q$exitroot@ykla:~ #
NOTE: Configuring authentication for SERVER mode.Enter the email address and password to use for the initial pgAdmin user account:Email address: your_email //输入你的邮件地址Password: your_new_password //输入你的登录密码Retype password://再次输入密码Starting pgAdmin 4. Please navigate to http://0.0.0.0:5050in your browser.
现在我们已经安装并运行了 pgAdmin4,并可以通过 http://ip:5050 访问 Web 控制面板: