Day2day Opportunism

まぁ、平たく言うと「雑記」がだらだらと・・・

PostgreSQL データーベースのコピー

何回もやっているのに毎回調べてる…きっと次も調べる

まずは、バックアップ。

-bash-3.2$ pg_dump base_db > base_db_20110923.dmp

Password:

-bash-3.2$

次にコピー先を作成しておく。(元がEUC-JPでシステムがUTF-8なので、文字コードEUC-JPで作成)

-bash-3.2$ createdb -E EUC_JP new_db

Password:

CREATE DATABASE

-bash-3.2$

バックアップしたものを新しいデーターベースへ

-bash-3.2$ psql new_db < base_db_20110923.dmp

Password:

SET

SET

COMMENT

CREATE LANGUAGE

SET

SET

SET

CREATE TABLE

ALTER TABLE

setval

--------

1531

(1 row)

CREATE TABLE

ALTER TABLE

ALTER TABLE

REVOKE

REVOKE

GRANT

GRANT

-bash-3.2$

結果確認のためpsqlで接続する。

-bash-3.2$ psql

Password:

Welcome to psql 8.1.4, the PostgreSQL interactive terminal.

Type: \copyright for distribution terms

\h for help with SQL commands

\? for help with psql commands

\g or terminate with semicolon to execute query

\q to quit

postgres=# \c new_db;

You are now connected to database "new_db".

new_db=# \d

List of relations

Schema | Name | Type | Owner

--------+----------------------------+----------+----------

public | accesslog_tbl | table | postgres

public | user_tbl | table | postgres

(53 rows)

new_db=# select count(*) from accesslog_tbl;

count

-------

84

(1 row)

new_db=#