1.本地登陸postgresql,建庫授權,設置密碼

成都創新互聯公司基于成都重慶香港及美國等地區分布式IDC機房數據中心構建的電信大帶寬,聯通大帶寬,移動大帶寬,多線BGP大帶寬租用,是為眾多客戶提供專業服務器托管報價,主機托管價格性價比高,為金融證券行業四川雅安服務器托管,ai人工智能服務器托管提供bgp線路100M獨享,G口帶寬及機柜租用的專業成都idc公司。
服務器本地登陸postgresql數據庫(默認是不需要密碼的)
postgres@localhost ~]$ psql
psql.bin (9.5.9)
Type "help" for help.
創建角色,并且給角色設置密碼:
postgres=# create user testwjw with password 'Zykj@5&^%996';
CREATE ROLE
修改數據庫用戶和密碼:
postgres=# alter user testwjw with password '558996';
ALTER ROLE
指定字符集創建數據庫testdb1,并且授權給testwjw
postgres=# create database testdb1 with encoding='utf8' owner=testwjw;
CREATE DATABASE
授權:
postgres=# grant all privileges on database testdb1 to testwjw;
GRANT
2.修改postgresql.conf文件中的端口和監聽主機:
postsql默認安裝后是監聽本機127.0.0.1 默認端口是5432,是不能夠遠程登陸的,所以要修改監聽主機地址,同時修改默認的端口為:36985
postgresql數據庫的配置文件是:postgresql.conf,所在位置是:postgresql初始化時所指定的data數據目錄下:
[postgres@localhost ~]$ ll /data/postgresql/data/postgresql.conf
-rw------- 1 postgres postgres 21305 Oct 3 11:18 /data/postgresql/data/postgresql.conf
[postgres@localhost ~]$ egrep "listen_addresses|5432"/data/postgresql/data/postgresql.conf
listen_addresses = 'localhost'# what IP address(es) to listen on;
port = 5432# (change requires restart)
修改監聽主機為*,端口為:36985
[postgres@localhost ~]$ egrep "listen_addresses|36985" /data/postgresql/data/postgresql.conf
listen_addresses = '*'# what IP address(es) to listen on;
port = 36985# (change requires restart)
修改配置文件pg_hba.conf ,允許遠程ip訪問本地數據庫,以及設置服務器本地登陸postgresql數據庫要求輸入密碼才可以登陸
[postgres@localhost ~]$ egrep "60.223.153.25|127.0.0.1" /data/postgresql/data/pg_hba.conf
host all all 60.223.153.25/32 trust
host all all 127.0.0.1/32 password
#host replication postgres 127.0.0.1/32 trust
允許 60.223.153.25ip訪問服務器postgresql數據庫
psql -Utestwjw -dpostgres -p36985 -h 127.0.0.1 這樣訪問數據庫127.0.0.1數據庫必須輸入密碼才可以
3.重啟postgresql服務生效:
[postgres@localhost ~]$ pg_ctl -D /data/postgresql/data -l /data/postgresql/log/postgres.log restart
waiting for server to shut down....LOG: received fast shutdown request
LOG: aborting any active transactions
LOG: autovacuum launcher shutting down
LOG: shutting down
LOG: database system is shut down
done
server stopped
server starting
[postgres@localhost ~]$ netstat -lntup|grep postgres
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
tcp 0 0 0.0.0.0:36985 0.0.0.0:* LISTEN 6472/postgres
4.登陸數據庫:
[postgres@localhost ~]$ psql
psql.bin: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
[postgres@localhost ~]$ psql -Utestwjw -dpostgres -p36985 -h 127.0.0.1
Password for user testwjw:
psql.bin: fe_sendauth: no password supplied
[postgres@localhost ~]$ psql -Utestwjw -dpostgres -p36985 -h 127.0.0.1
Password for user testwjw:
psql.bin (9.5.9)
Type "help" for help.
postgres=> \q
[postgres@localhost ~]$ psql -Utestwjw -dtestdb1 -p36985 -h 127.0.0.1
Password for user testwjw:
psql.bin (9.5.9)
Type "help" for help.
testdb1=> select * from t;
id | nan | note
----+-----+-------
1 | t | TRUE
2 | f | FALSE
3 | t | tRue
4 | f | fAlse
11 | | null
11 | | NULL
7 | t | 't'
8 | f | 'f'
9 | t | 'yes'
10 | f | '0'
(10 rows)
testdb1=>
[postgres@localhost ~]$ psql -Utestwjw -dtestdb1 -p36985
psql.bin (9.5.9)
Type "help" for help.
testdb1=> \q
[postgres@localhost ~]$ psql -Utestwjw -dtestdb2 -p36985
psql.bin (9.5.9)
Type "help" for help.
testdb2=> \q
網站名稱:postgresql數據庫設置遠程登陸賬戶和密碼
URL標題:http://www.yijiale78.com/article8/ghdcop.html
成都網站建設公司_創新互聯,為您提供云服務器、網頁設計公司、移動網站建設、自適應網站、關鍵詞優化、網站設計公司
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯