ii postgresql-9.3 9.3.4-1 amd64 object-relational SQL database, version 9.3 server
ii postgresql-client-9.3 9.3.4-1 amd64 front-end programs for PostgreSQL 9.3
ii postgresql-client-common 154 all manager for multiple PostgreSQL client versions
ii postgresql-common 154 all PostgreSQL database-cluster manager
# passwd postgres
$ su postgres
$ createuser scott -P
$ createdb city
$ psql
postgres=# select * from pg_user;
dropuser scott
createuser scott
外部からのアクセスを許可する。
/etc/postgresql/9.3/main/postgresql.conf
listen_addresses = '*'
/etc/postgresql/9.1/main/pg_hba.conf
# "local" is for Unix domain socket connections only
local all all trust
# IPv4 local connections:
host all all 127.0.0.1/32 trust
host all all 0.0.0.0/0 trust
データベースクラスタの作成
/usr/lib/postgresql/8.4/bin/initdb -E UTF-8 -D /usr/local/pgsql/data
以下を使用してデータベースサーバを起動することができます。
/usr/lib/postgresql/8.4/bin/postgres -D /usr/local/pgsql/data
または
/usr/lib/postgresql/8.4/bin/pg_ctl -D /usr/local/pgsql/data -l logfile start
su postgres
createdb city
psql -l city
psql -f postgre_create.sql -U scott city
psql -f postgre_insert.sql -U scott city
psql -f postgre_read.sql -U scott city
データベースの作成
createdb book -U scott
dropdb book -U scott
psql book -U scott
PHP
# apt install php-pgsql
# pacman -S php-pgsql
/etc/php/php.ini
extension=pgsql.so
Python
python-pygresql
# pacman -S python-psycopg2
sudo apt install python3-psycopg2
Perl
libdbd-pg-perl
Ruby
libdbd-pg-ruby
Arch Linux
$ gem install pg
$ gem install rdbi
$ gem install rdbi-driver-postgresql
Lua
# pacman -S lua-sql-postgres
Haskell
ii libghc-hdbc-postgresql-dev 2.3.2.1-3build1 amd64 PostgreSQL HDBC (Haskell Database Connectivity) Driver for GHC
Gauche
Gauche-dbd-pg-0.2.1.tgz
trunck.tar.gz を持ってきてトライしたのですが、
うまくいきませんでした。
guile
guile-pg
Tcl
PostgreSQL with Tcl
node.js
# npm install pg
Java
libpg-java
org.postgresql.util.PSQLException:
Your security policy has prevented the connection from being attempted.
You probably need to grant the connect java.net.SocketPermission
to the database server host and port that you wish to connect to.
/etc/tomcat6/policy.d/04webapps.policy
ermission java.security.AllPermission;
/usr/share/java/postgresql-jdbc3-8.2.jar
go
go get github.com/lib/pq
/home/uchida/go/src/github.com/lib/pq
Arch Linux
$ yaourt -Sb postgresql-jdbc
C#
ii libmono-npgsql4.0-cil 2.10.8.1-5ubuntu2 all Mono Npgsql library (for CLI 4.0)
$ psql -h nlf132 -U scott city
$ psql -h localhost -U scott city
Arch Linux
# pacman -S postgresql
# passwd postgres
/etc/locale.gen
# locale-gen
$ su postgres
$ initdb --locale en_US.UTF-8 -E UTF8 -D '/var/lib/postgres/data'
# systemctl start postgresql
Export
pg_dump -U USERNAME DBNAME > dbexport.pgsql
pg_dump -U scott city > dbexport.pgsql
Import
psql -U USERNAME DBNAME < dbexport.pgsql
createdb city
psql -U scott city < dbexport.pgsql
psql の使い方
$ psql -U postgres
psql (9.5.4)
Type "help" for help.
postgres=# \c city;
You are now connected to database "city" as user "postgres".
city=# select * from cities;
id | name | population | date_mod
-------+--------+------------+------------
t3461 | 広島 | 47800 | 2003-05-20
t3468 | 大竹 | 78400 | 2003-10-26
t3467 | 三次 | 81200 | 2003-07-23
t3466 | 竹原 | 51800 | 2003-01-21
t3469 | 府中 | 23400 | 2003-12-15
t3465 | 尾道 | 39100 | 2003-08-04
t3463 | 東広島 | 21600 | 2003-06-14
t3464 | 呉 | 83600 | 2003-09-09
t3462 | 福山 | 93500 | 2003-06-12
(9 rows)
city=# \q
$ psql -U scott city
psql (9.6.4)
"help" でヘルプを表示します.
city=> \dt;
リレーションの一覧
スキーマ | 名前 | 型 | 所有者
----------+--------+----------+--------
public | cities | テーブル | scott
(1 行)
city=> \d cities;
テーブル "public.cities"
列 | 型 | 修飾語
------------+-----------------------+----------
id | character varying(10) | not null
name | text |
population | integer |
date_mod | date |
インデックス:
"cities_pkey" PRIMARY KEY, btree (id)
city=> \q
result_aa
outarea_aa
outarea_bb
outarea_cc
outarea_dd
outarea_ee
outarea_ff
outarea_gg
outarea_hh
Return
Dec/19/2023 AM 08:15