ubuntu下postgreSQL安裝配置

1、安裝並配置,並設置遠程登錄的用戶名和密碼html

一、安裝postgreSQLsql

sudo apt-get update數據庫

sudo apt-get install postgresql-9.4ubuntu

  • 在Ubuntu下安裝Postgresql後,會自動註冊爲服務,並隨操做系統自動啓動。
  • 在Ubuntu下安裝Postgresql後,會自動添加一個名爲postgres的操做系統用戶,密碼是隨機的。而且會自動生成一個名字爲postgres的數據庫,用戶名也爲postgres,密碼也是隨機的。

二、修改postgres數據庫用戶的密碼爲123456tcp

打開客戶端工具(psql)工具

sudo -u postgres psqlpost

  • 其中,sudo -u postgres 是使用postgres 用戶登陸的意思
  • PostgreSQL數據默認會建立一個postgres的數據庫用戶做爲數據庫的管理員,密碼是隨機的

postgres=# ALTER USER postgres WITH PASSWORD '123456'; spa

  • postgres=#爲PostgreSQL下的命令提示符,--注意最後的分號;

三、退出PostgreSQL psql客戶端操作系統

postgres=# \q命令行

四、修改ubuntu操做系統的postgres用戶的密碼(密碼要與數據庫用戶postgres的密碼相同)

切換到root用戶

su root

刪除PostgreSQL用戶密碼

sudo passwd -d postgres

  • passwd -d 是清空指定用戶密碼的意思

設置PostgreSQL系統用戶的密碼

sudo -u postgres passwd

按照提示,輸入兩次新密碼

  • 輸入新的 UNIX 密碼
  • 從新輸入新的 UNIX 密碼
  • passwd:已成功更新密碼

五、修改PostgresSQL數據庫配置實現遠程訪問

vi /etc/postgresql/9.4/main/postgresql.conf

1.監放任何地址訪問,修改鏈接權限

#listen_addresses = 'localhost' 改成 listen_addresses = '*'

2.啓用密碼驗證

#password_encryption = on 改成 password_encryption = on

vi /etc/postgresql/9.4/main/pg_hba.conf

在文檔末尾加上如下內容

host all all 0.0.0.0 0.0.0.0 md5

六、重啓服務

/etc/init.d/postgresql restart

七、5432端口的防火牆設置

5432爲postgreSQL默認的端口

iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 5432 -j ACCEPT

2、內部登陸,管理數據庫、新建數據庫、用戶和密碼

一、登陸postgre SQL數據庫

psql -U postgres -h 127.0.0.1

二、建立新用戶zhangps,但不給建數據庫的權限

postgres=# create user "zhangps" with password '123456' nocreatedb;

  • 用戶名處是雙引號

三、創建數據庫,並指定全部者

postgres=#create database "testdb" with owner = "zhangps";

3、外部登陸,管理數據庫、新建數據庫、用戶和密碼

一、在外部命令行的管理命令,建立用戶pencil

sudo -u postgres createuser -D -P pencil

  • 輸入新的密碼:
  • 再次輸入新的密碼:

二、創建數據庫(tempdb),並指定全部者爲(pencil)

sudo -u postgres createdb -O pencil tempdb

  • -O設定全部者爲pencil

參考:http://blog.sina.com.cn/s/blog_6af33caa0100ypck.html

相關文章
相關標籤/搜索