最近の履歴からメモ
(UTF-8)でデータベースクラスタを初期化したPostgreSQLで、EUC-JPのデータベースを作成する。
$ createdb -U postgres -h localhost --encoding EUC_JP --locale=ja_JP.EUC_JP --template=template0 {dbname}
特権なしのユーザを作成
$ createuser -U postgres -h localhost --no-createdb --no-createrole --pwprompt {username}
サーバ間でデータベースをコピー(dumpとrestore)
$ for DBNAME in db_no1 db_no2 db_no3 db_no4 db_no5; do pg_dump --create --format=p -U postgres -h dbhost2 $DBNAME | psql -U postgres -h localhost $DBNAME; done;
※上期で、「dbhost2」サーバから「localhost」に、「db_no1」〜「db_no5」の5つのデータベースを処理
存在するデータベースの一覧を表示(名前だけ羅列)
$ psql --user=postgres --list --tuples-only --pset="format=unaligned" --pset="fieldsep=," | sed 's!^postgres=CTc/postgres$!!g' | cut --delimiter="," --fields=1 | sed -e 's/^template[01]$//g' -e '/^$/d'