LoginSignup
0
0

More than 5 years have passed since last update.

Windows10上でインストールせずにPostgreSQL10.6を動かす

Posted at

何度も調べるのでまとめました。他の環境でもほぼ同じ感じだと思います。

  1. https://www.postgresql.org/download/windows/
    にアクセスし、zip archiveのリンクをクリック
    1.PNG

  2. Version10.6の Win x86-64 をダウンロード
    2.PNG

  3. ダウンロードしたzipを c:\bin に解凍(C:\bin\pgsqlとなる)

  4. Windowsキー+Rでcmdを実行し、C:\bin\pgsql に移動
    3.PNG

    カレントディレクトリの移動
    > cd \bin\pgsql
    
  5. 以下のコマンドを実行しデータベースを初期化する(途中2回パスワードを聞かれるので設定したいパスワードを入力する)

    データベースの初期化
    > bin\initdb -U postgres -A password -E utf8 -W -D data
    
    • -U はデータベースの所有者
    • -A password は認証方式をパスワード認証にする指定
    • -E utf8 は文字コードをUTF-8にする指定
    • -W はパスワードを手入力する指定
    • -D data はデータフォルダを C:\bin\pgsql\data にする指定
  6. 以上で準備は完了。起動するには以下のコマンドを実行

    データベースサーバの起動
    > bin\pg_ctl -D data -l pg.log start
    
    • -l pg.log はログを C:\bin\pgsql\pg.log に出力する指定
  7. SQLを実行するには以下のコマンド(パスワードを聞かれるので設定したパスワードを入力する)

    SQLの実行用シェルを起動
    > bin\psql -U postgres
    
    データベース一覧
    postgres=# \l
                                             データベース一覧
    名前    |  所有者  | エンコーディング |      照合順序      | Ctype(変換演算子)  |     アクセス権限
    -----------+----------+------------------+--------------------+--------------------+-----------------------
    postgres  | postgres | UTF8             | Japanese_Japan.932 | Japanese_Japan.932 |
    template0 | postgres | UTF8             | Japanese_Japan.932 | Japanese_Japan.932 | =c/postgres          +
           |          |                  |                    |                    | postgres=CTc/postgres
    template1 | postgres | UTF8             | Japanese_Japan.932 | Japanese_Japan.932 | =c/postgres          +
           |          |                  |                    |                    | postgres=CTc/postgres
    (3 行)
    

    よく使うコマンド

    データベース切り替え
    postgres=# \c postgres
    データベース "postgres" にユーザ "postgres" として接続しました。
    
    テーブル一覧
    postgres=# \dt
    リレーションが見つかりませんでした。
    
    テーブル作成
    postgres=# create table test(a int, b text);
    CREATE TABLE
    
    テーブル一覧
    postgres=# \dt
           リレーション一覧
    スキーマ | 名前 |    型    |  所有者
    ----------+------+----------+----------
    public   | test | テーブル | postgres
    (1 行)
    
    テーブル定義
    postgres=# \d test
                テーブル "public.test"
    列 |   型    | 照合順序 | Null 値を許容 | デフォルト
    ----+---------+----------+---------------+------------
    a  | integer |          |               |
    b  | text    |          |               |
    
    終了
    postgres=# \q
    
  8. 停止するには以下のコマンドを実行

    データベースサーバの停止
    > bin\pg_ctl -D data stop
    
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0