使用PostgreSQL

使用PostgreSQL

下載頁面:http://www.enterprisedb.com/products-services-training/pgdownload

目前建議用 docker 快速架設

使用 docker-compose.yml

一樣要建立 volumn 避免重啟後資料消失

# Use postgres/example user/password credentials
version: '3.1'

services:

  db:
    image: postgres
    restart: always
    volumes:
      - "./dbdata:/var/lib/postgresql/data"
    ports:
      - 5432:5432
    environment:
      POSTGRES_USER: superuser
      POSTGRES_PASSWORD: example

  adminer:
    image: adminer
    restart: always
    ports:
      - 8080:8080

https://hub.docker.com/_/postgres

安裝

https://www.godaddy.com/garage/how-to-install-postgresql-on-ubuntu-14-04/

之後輸入以下進入postgres使用者

進入psql

更改預設密碼,進入psql後輸入以下

Mac安裝

https://medium.com/@Umesh_Kafle/postgresql-and-postgis-installation-in-mac-os-87fa98a6814d

1.使用pgAdmin

https://www.pgadmin.org/download/

一個可視化的網頁瀏覽工具

如果使用本地連線時輸入localhost比較好,因為有時127.0.0.1無作用

如果出現can't connect application server,重新啟動一次即可。

如要查看TABLE

如要查看row

執行SQL

點選 Tools 然後按 Query Tool

PgAdmin連線遠端主機的DB

1.設定pg_hba.conf

分別為DB, User, IP 與方法

2.設定postgresql.conf

3.重啟:

4.開啟遠端主機防火牆,port:5432

然後即可使用PgAdmin遠端連線。

可參考:https://cloud.google.com/community/tutorials/setting-up-postgres

2.使用SQL shell ( psql )

輸入psql <資料庫名稱>

使用Log

預設只會存在psql 操作的log

log路徑:/var/log/postgresql/postgresql-10-main.log

1.首先要設定config: /etc/postgresql/10/main/postgresql.conf

2.

3.重啟config

參考至:

http://www.postgresql.org/docs/8.3/static/tutorial-table.html

中文版:

http://twpug.net/docs/postgresql-doc-8.0-zh_TW/tutorial-populate.html

Last updated

Was this helpful?