0
0

More than 1 year has passed since last update.

postgreSQLのコマンドを外部から実行

Posted at

やりたい事

postgreSQLのパラメータをテキストファイルに出力するため
コマンドライン(外部)からpostgreSQLにコマンドを実行したい...

やってみる

1.SQLの実行ファイルをvimで作成

コマンドライン上でvimなどのエディタを使用し、SQL実行ファイルを作成します
今回のケースではpostgreSQLのパラメータを呼び出します。ファイル名はparameter.sqlとします。

# parameter.sql
select name, setting, unit from pg_settings;
2. parameter.sqlを実行し、テキストファイルに出力
psql -f parameter.sql -U ユーザ名 -d データベース名 -h ホスト > postgresql-config.txt

コマンドライン上から一時的にpostgreSQLにログインし、パラメータをpostgresql-config.txtに出力する
という処理が完了しました。

このように -f sqlファイルと指定することでファイルからコマンドを読み込んで実行する事ができます。

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