Once you have created a database, you can access it by: データベースを作成した後、以下によってアクセスできます。
Running the <productname>PostgreSQL</productname> interactive terminal program, called <application><firstterm>psql</firstterm></application>, which allows you to interactively enter, edit, and execute <acronym>SQL</acronym> commands. psqlというPostgreSQL対話式端末プログラムを実行。 これにより、対話式にSQLコマンドの入力、編集、実行を行うことができます。
Using an existing graphical frontend tool like <application>pgAdmin</application> or an office suite with <acronym>ODBC</acronym> or <acronym>JDBC</acronym> support to create and manipulate a database. These possibilities are not covered in this tutorial. pgAdminのような既存のグラフィカルなフロントエンドツールや、ODBCあるいはJDBCを備えたオフィススイートなどを使用して、データベースの作成や操作を行う。 これらについてはこのチュートリアルでは取り上げません。
Writing a custom application, using one of the several available language bindings. These possibilities are discussed further in <xref linkend="client-interfaces"/>. 複数の使用可能な言語の1つを使用した、独自のアプリケーションの作成。 これについては、パート IVで詳しく説明します。
You probably want to start up <command>psql</command> to try
the examples in this tutorial. It can be activated for the
<literal>mydb</literal> database by typing the command:
このチュートリアルの例を試すには、psqlから始めることを勧めます。
以下のコマンドを入力することで、mydbデータベースに対して実行できます。
$psql mydb
If you do not supply the database name then it will default to your
user account name. You already discovered this scheme in the
previous section using <command>createdb</command>.
データベース名を与えなかった場合、データベース名はデフォルトでユーザアカウント名となります。
この仕組みについては前節でcreatedbを使って既に説明しています。
In <command>psql</command>, you will be greeted with the following
message:
psqlでは、始めに以下のメッセージが表示されます。
psql (18.0) Type "help" for help. mydb=>
<indexterm><primary>superuser</primary></indexterm> The last line could also be: 最後の行は以下のようになっているかもしれません。
mydb=#
That would mean you are a database superuser, which is most likely the case if you installed the <productname>PostgreSQL</productname> instance yourself. Being a superuser means that you are not subject to access controls. For the purposes of this tutorial that is not important. これは、データベーススーパーユーザであることを示します。 自身でPostgreSQLのインスタンスをインストールした場合にはこのようになっている可能性が高いです。 スーパーユーザであることは、アクセス制御の支配を受けないことを意味します。 このチュートリアルの実施においては、これは重要ではありません。
If you encounter problems starting <command>psql</command>
then go back to the previous section. The diagnostics of
<command>createdb</command> and <command>psql</command> are
similar, and if the former worked the latter should work as well.
psqlの起動に問題が発生した場合は、前節に戻ってください。
createdbの診断とpsqlの診断方法は似ており、前者が動作すれば後者も同様に動作するはずです。
The last line printed out by <command>psql</command> is the
prompt, and it indicates that <command>psql</command> is listening
to you and that you can type <acronym>SQL</acronym> queries into a
work space maintained by <command>psql</command>. Try out these
commands:
psqlが最後に出力する行はプロンプトで、psqlが入力を監視していること、psqlが管理する作業領域にSQL問い合わせを入力できることを示しています。
以下のコマンドを試してください。
mydb=>SELECT version();version ------------------------------------------------------------------------------------------ PostgreSQL 18.0 on x86_64-pc-linux-gnu, compiled by gcc (Debian 4.9.2-10) 4.9.2, 64-bit (1 row)mydb=>SELECT current_date;date ------------ 2016-01-07 (1 row)mydb=>SELECT 2 + 2;?column? ---------- 4 (1 row)
The <command>psql</command> program has a number of internal
commands that are not SQL commands. They begin with the backslash
character, <quote><literal>\</literal></quote>.
For example,
you can get help on the syntax of various
<productname>PostgreSQL</productname> <acronym>SQL</acronym>
commands by typing:
psqlプログラムは、SQLコマンドではない、多くの内部コマンドを持っています。
それらはバックスラッシュ文字「\」から始まります。
例えば、各種PostgreSQL SQLコマンドの構文に関するヘルプを以下のようにして得ることができます。
mydb=>\h
To get out of <command>psql</command>, type:
psqlを終了するには、以下を入力します。
mydb=>\q
and <command>psql</command> will quit and return you to your
command shell. (For more internal commands, type
<literal>\?</literal> at the <command>psql</command> prompt.) The
full capabilities of <command>psql</command> are documented in
<xref linkend="app-psql"/>. In this tutorial we will not use these
features explicitly, but you can use them yourself when it is helpful.
psqlは終了し、コマンドシェルに戻ります。
(他の内部コマンドについてはpsqlのプロンプトで\?を入力してください。)
psqlの完全な能力についてはpsqlで説明されています。
このチュートリアルではこれらの機能は明示的に使用しませんが、便利な場合はこれらを使用しても構いません。