-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp-psql.html
More file actions
5605 lines (5596 loc) · 478 KB
/
app-psql.html
File metadata and controls
5605 lines (5596 loc) · 478 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>psql</title><link rel="stylesheet" type="text/css" href="stylesheet.css" /><link rev="made" href="pgsql-docs@lists.postgresql.org" /><meta name="generator" content="DocBook XSL Stylesheets Vsnapshot" /><link rel="prev" href="app-pgverifybackup.html" title="pg_verifybackup" /><link rel="next" href="app-reindexdb.html" title="reindexdb" /><meta name="viewport" content="width=device-width,initial-scale=1.0" /></head><body id="docContent" class="container-fluid col-10"><div class="other_version"><a href="https://www.postgresql.jp/document/">バージョンごとのドキュメント一覧</a></div><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="4" align="center"><a accesskey="h" href="index.html">PostgreSQL 18.3文書</a></th></tr><tr><td width="10%" align="left"></td><td width="10%" align="left"></td><td width="60%" align="center"><a href="reference-client.html" title="PostgreSQLクライアントアプリケーション">PostgreSQLクライアントアプリケーション</a></td><td width="20%" align="right"><div class="actions"><a class="issue" title="github" href="https://github.com/pgsql-jp/jpug-doc/issues/new?template=bug_report.yml&what-happened=version 18.3 : app-psql.html">誤訳等の報告
</a></div></td></tr><tr><td width="10%" align="left"><a accesskey="p" href="app-pgverifybackup.html" title="pg_verifybackup">前へ</a> </td><td width="10%" align="left"><a accesskey="u" href="reference-client.html" title="PostgreSQLクライアントアプリケーション">上へ</a></td><td width="60%" align="center"><span class="application">psql</span></td><td width="20%" align="right"> <a accesskey="n" href="app-reindexdb.html" title="reindexdb">次へ</a></td></tr></table><hr /></div><div class="refentry" id="APP-PSQL"><div class="titlepage"></div><a id="id-1.9.4.21.1" class="indexterm"></a><div class="refnamediv"><h2><span class="refentrytitle"><span class="application">psql</span></span></h2><p><span class="application">psql</span> —
<span class="original">
<productname>PostgreSQL</productname> interactive terminal
</span>
<span class="productname">PostgreSQL</span>の対話的ターミナル
</p></div><div class="refsynopsisdiv"><h2>概要</h2><div class="cmdsynopsis"><p id="id-1.9.4.21.4.1"><code class="command">psql</code> [<em class="replaceable"><code>option</code></em>...] [<em class="replaceable"><code>dbname</code></em>
[<em class="replaceable"><code>username</code></em>]]</p></div></div><div class="refsect1" id="id-1.9.4.21.5"><h2>説明</h2><span class="original">
<title>Description</title>
</span><p>
<span class="original">
<application>psql</application> is a terminal-based front-end to
<productname>PostgreSQL</productname>. It enables you to type in
queries interactively, issue them to
<productname>PostgreSQL</productname>, and see the query results.
Alternatively, input can be from a file or from command line
arguments. In addition, <application>psql</application> provides a
number of meta-commands and various shell-like features to
facilitate writing scripts and automating a wide variety of tasks.
</span>
<span class="application">psql</span>とは<span class="productname">PostgreSQL</span>のターミナル型フロントエンドです。
対話的に問い合わせを入力し、それを<span class="productname">PostgreSQL</span>に対して発行して、結果を確認することができます。
また、ファイルまたはコマンドライン引数から入力を読み込むことも可能です。
さらに、<span class="application">psql</span>は、スクリプトの記述を簡便化したり、様々なタスクを自動化したりする、いくつものメタコマンドとシェルに似た各種の機能を備えています。
</p></div><div class="refsect1" id="R1-APP-PSQL-3"><h2>オプション</h2><span class="original">
<title>Options</title>
</span><div class="variablelist"><dl class="variablelist"><dt id="APP-PSQL-OPTION-ECHO-ALL"><span class="term"><code class="option">-a</code><br /></span><span class="term"><code class="option">--echo-all</code></span> <a href="#APP-PSQL-OPTION-ECHO-ALL" class="id_link">#</a></dt><dd><p>
<span class="original">
Print all nonempty input lines to standard output as they are read.
(This does not apply to lines read interactively.) This is
equivalent to setting the variable <varname>ECHO</varname> to
<literal>all</literal>.
</span>
読み込んだ全ての空でない入力行を標準出力に表示します。
(これは対話式に読み込まれる行には適用されません。)
これは<code class="varname">ECHO</code>変数を<code class="literal">all</code>に設定するのと同じ意味を持ちます。
</p></dd><dt id="APP-PSQL-OPTION-NO-ALIGN"><span class="term"><code class="option">-A</code><br /></span><span class="term"><code class="option">--no-align</code></span> <a href="#APP-PSQL-OPTION-NO-ALIGN" class="id_link">#</a></dt><dd><p>
<span class="original">
Switches to unaligned output mode. (The default output mode is
<literal>aligned</literal>.) This is equivalent to
<command>\pset format unaligned</command>.
</span>
位置揃えなしの出力モードに切り替えます。
(デフォルトの出力モードは<code class="literal">aligned</code>(位置揃えあり)です。)
これは<code class="command">\pset format unaligned</code>と同等です。
</p></dd><dt id="APP-PSQL-OPTION-ECHO-ERRORS"><span class="term"><code class="option">-b</code><br /></span><span class="term"><code class="option">--echo-errors</code></span> <a href="#APP-PSQL-OPTION-ECHO-ERRORS" class="id_link">#</a></dt><dd><p>
<span class="original">
Print failed SQL commands to standard error output. This is
equivalent to setting the variable <varname>ECHO</varname> to
<literal>errors</literal>.
</span>
失敗したSQLコマンドを標準エラー出力に出力します。
これは<code class="varname">ECHO</code>変数を<code class="literal">errors</code>に設定するのと同等です。
</p></dd><dt id="APP-PSQL-OPTION-COMMAND"><span class="term"><code class="option">-c <em class="replaceable"><code>command</code></em></code><br /></span><span class="term"><code class="option">--command=<em class="replaceable"><code>command</code></em></code></span> <a href="#APP-PSQL-OPTION-COMMAND" class="id_link">#</a></dt><dd><p>
<span class="original">
Specifies that <application>psql</application> is to execute the given
command string, <replaceable class="parameter">command</replaceable>.
This option can be repeated and combined in any order with
the <option>-f</option> option. When either <option>-c</option>
or <option>-f</option> is specified, <application>psql</application>
does not read commands from standard input; instead it terminates
after processing all the <option>-c</option> and <option>-f</option>
options in sequence.
</span>
<span class="application">psql</span>に対し、指定のコマンド文字列<em class="replaceable"><code>command</code></em>を実行するよう指示します。
このオプションは繰り返すことができ、また<code class="option">-f</code>オプションと任意の順序で組み合わせることができます。
<code class="option">-c</code>または<code class="option">-f</code>が指定されると、<span class="application">psql</span>は標準入力からコマンドを読み取りません。
その代わりに、すべての<code class="option">-c</code>オプションおよび<code class="option">-f</code>オプションを順に処理した後、終了します。
</p><p>
<span class="original">
<replaceable class="parameter">command</replaceable> must be either
a command string that is completely parsable by the server (i.e.,
it contains no <application>psql</application>-specific features),
or a single backslash command. Thus you cannot mix
<acronym>SQL</acronym> and <application>psql</application>
meta-commands within a <option>-c</option> option. To achieve that,
you could use repeated <option>-c</option> options or pipe the string
into <application>psql</application>, for example:
</span>
<em class="replaceable"><code>command</code></em>は、サーバで完全に解析可能な(つまり、<span class="application">psql</span>特有の機能は含まない)コマンド文字列、もしくは、バックスラッシュコマンド1つである必要があります。
このため、<code class="option">-c</code>オプション内では<acronym class="acronym">SQL</acronym>と<span class="application">psql</span>メタコマンドを混在させることはできません。
これらを同時に使用するには、<code class="option">-c</code>オプションを繰り返し利用するか、あるいはパイプを使って文字列を<span class="application">psql</span>に渡します。
例えば、
</p><pre class="programlisting">
psql -c '\x' -c 'SELECT * FROM foo;'
</pre><p>
<span class="original">
or
</span>
あるいは
</p><pre class="programlisting">
echo '\x \\ SELECT * FROM foo;' | psql
</pre><p>
<span class="original">
(<literal>\\</literal> is the separator meta-command.)
</span>
のようにします(<code class="literal">\\</code>はメタコマンドの区切り文字です。)
</p><p>
<span class="original">
Each <acronym>SQL</acronym> command string passed
to <option>-c</option> is sent to the server as a single request.
Because of this, the server executes it as a single transaction even
if the string contains multiple <acronym>SQL</acronym> commands,
unless there are explicit <command>BEGIN</command>/<command>COMMIT</command>
commands included in the string to divide it into multiple
transactions. (See <xref linkend="protocol-flow-multi-statement"/>
for more details about how the server handles multi-query strings.)
</span>
<code class="option">-c</code>に渡される各<acronym class="acronym">SQL</acronym>のコマンド文字列は、単一の要求としてサーバに送信されます。
このため、トランザクションを複数に分ける<code class="command">BEGIN</code>/<code class="command">COMMIT</code>コマンドが明示的に文字列内に含まれない限り、文字列内に複数の<acronym class="acronym">SQL</acronym>コマンドが含まれていたとしても、サーバはそれを1つのトランザクションとして実行します。
(複数問い合わせの文字列をどのようにサーバが処理するかについて、詳しくは<a class="xref" href="protocol-flow.html#PROTOCOL-FLOW-MULTI-STATEMENT" title="54.2.2.1. 簡易問い合わせでの複文">54.2.2.1</a>を参照してください。)
</p><p>
<span class="original">
If having several commands executed in one transaction is not desired,
use repeated <option>-c</option> commands or feed multiple commands to
<application>psql</application>'s standard input,
either using <application>echo</application> as illustrated above, or
via a shell here-document, for example:
</span>
1つのトランザクションで複数のコマンドを実行することが望ましくない場合は、繰り返し<code class="option">-c</code>コマンドを使用するか、あるいは、上記のように<span class="application">echo</span>を使用するか、以下の例のようにシェルのヒアドキュメントを介して<span class="application">psql</span>の標準入力に複数のコマンドを送ります。
</p><pre class="programlisting">
psql <<EOF
\x
SELECT * FROM foo;
EOF
</pre></dd><dt id="APP-PSQL-OPTION-CSV"><span class="term"><code class="option">--csv</code></span> <a href="#APP-PSQL-OPTION-CSV" class="id_link">#</a></dt><dd><p>
<span class="original">
Switches to <acronym>CSV</acronym> (Comma-Separated Values) output
mode. This is equivalent to <command>\pset format csv</command>.
</span>
<acronym class="acronym">CSV</acronym>(カンマ区切り値)出力モードに切り替えます。
これは<code class="command">\pset format csv</code>と同等です。
</p></dd><dt id="APP-PSQL-OPTION-DBNAME"><span class="term"><code class="option">-d <em class="replaceable"><code>dbname</code></em></code><br /></span><span class="term"><code class="option">--dbname=<em class="replaceable"><code>dbname</code></em></code></span> <a href="#APP-PSQL-OPTION-DBNAME" class="id_link">#</a></dt><dd><p>
<span class="original">
Specifies the name of the database to connect to. This is
equivalent to specifying <replaceable
class="parameter">dbname</replaceable> as the first non-option
argument on the command line. The <replaceable>dbname</replaceable>
can be a <link linkend="libpq-connstring">connection string</link>.
If so, connection string parameters will override any conflicting
command line options.
</span>
接続するデータベースの名前を指定します。
コマンドラインでオプション以外の最初の引数として<em class="replaceable"><code>dbname</code></em>を指定するのと同じ効力を持ちます。
<em class="replaceable"><code>dbname</code></em>は<a class="link" href="libpq-connect.html#LIBPQ-CONNSTRING" title="32.1.1. 接続文字列">接続文字列</a>でも構いません。
その場合、接続文字列パラメータは衝突するコマンドラインオプションに優先します。
</p></dd><dt id="APP-PSQL-OPTION-ECHO-QUERIES"><span class="term"><code class="option">-e</code><br /></span><span class="term"><code class="option">--echo-queries</code></span> <a href="#APP-PSQL-OPTION-ECHO-QUERIES" class="id_link">#</a></dt><dd><p>
<span class="original">
Copy all SQL commands sent to the server to standard output as well.
This is equivalent
to setting the variable <varname>ECHO</varname> to
<literal>queries</literal>.
</span>
サーバに送られるすべてのSQLコマンドを標準出力にも送ります。
<code class="varname">ECHO</code>変数を<code class="literal">queries</code>に設定するのと同じ効力を持ちます。
</p></dd><dt id="APP-PSQL-OPTION-ECHO-HIDDEN"><span class="term"><code class="option">-E</code><br /></span><span class="term"><code class="option">--echo-hidden</code></span> <a href="#APP-PSQL-OPTION-ECHO-HIDDEN" class="id_link">#</a></dt><dd><p>
<span class="original">
Echo the actual queries generated by <command>\d</command> and other backslash
commands. You can use this to study <application>psql</application>'s
internal operations. This is equivalent to
setting the variable <varname>ECHO_HIDDEN</varname> to <literal>on</literal>.
</span>
<code class="command">\d</code>やその他のバックスラッシュコマンドによって生成される実際の問い合わせを表示します。
これを使って、<span class="application">psql</span>の内部動作を調べることができます。
これは変数<code class="varname">ECHO_HIDDEN</code>を<code class="literal">on</code>に設定するのと同じ効力を持ちます。
</p></dd><dt id="APP-PSQL-OPTION-FILE"><span class="term"><code class="option">-f <em class="replaceable"><code>filename</code></em></code><br /></span><span class="term"><code class="option">--file=<em class="replaceable"><code>filename</code></em></code></span> <a href="#APP-PSQL-OPTION-FILE" class="id_link">#</a></dt><dd><p>
<span class="original">
Read commands from the
file <replaceable class="parameter">filename</replaceable>,
rather than standard input.
This option can be repeated and combined in any order with
the <option>-c</option> option. When either <option>-c</option>
or <option>-f</option> is specified, <application>psql</application>
does not read commands from standard input; instead it terminates
after processing all the <option>-c</option> and <option>-f</option>
options in sequence.
Except for that, this option is largely equivalent to the
meta-command <command>\i</command>.
</span>
標準入力ではなく、ファイル<em class="replaceable"><code>filename</code></em>からコマンドを読み取ります。
このオプションは繰り返すことができ、また<code class="option">-c</code>オプションと任意の順序で組み合わせることができます。
<code class="option">-c</code>または<code class="option">-f</code>が指定されると、<span class="application">psql</span>は標準入力からコマンドを読み取りません。
その代わりに、すべての<code class="option">-c</code>オプションおよび<code class="option">-f</code>オプションを順に処理した後、終了します。
その点を除けば、このオプションは<code class="command">\i</code>メタコマンドとほぼ同等です。
</p><p>
<span class="original">
If <replaceable>filename</replaceable> is <literal>-</literal>
(hyphen), then standard input is read until an EOF indication
or <command>\q</command> meta-command. This can be used to intersperse
interactive input with input from files. Note however that Readline
is not used in this case (much as if <option>-n</option> had been
specified).
</span>
<em class="replaceable"><code>filename</code></em>に<code class="literal">-</code>(ハイフン)を指定すると、標準入力からEOFを示すもの、または<code class="command">\q</code>メタコマンドまで読み取られます。
これは対話的入力をファイルからの入力と混在させるために使うことができます。
ただし、この場合、Readlineは使われないことに注意してください(<code class="option">-n</code>が指定された場合と同様です)。
</p><p>
<span class="original">
Using this option is subtly different from writing <literal>psql
&lt; <replaceable
class="parameter">filename</replaceable></literal>. In general,
both will do what you expect, but using <literal>-f</literal>
enables some nice features such as error messages with line
numbers. There is also a slight chance that using this option will
reduce the start-up overhead. On the other hand, the variant using
the shell's input redirection is (in theory) guaranteed to yield
exactly the same output you would have received had you entered
everything by hand.
</span>
このオプションを指定するのと、<code class="literal">psql < <em class="replaceable"><code>filename</code></em></code>と入力するのでは、微妙に動作が異なります。
一般的には、両者とも期待通りの動作を行いますが、<code class="literal">-f</code>を使用した場合は、エラーメッセージに行番号を付けるなどいくつか便利な機能が有効になります。
また、このオプションを使用した場合、起動時のオーバーヘッドが減少する可能性が若干あります。
一方、シェルの入力リダイレクションを使用する方法では、(理論的には)全て手作業で入力した場合の出力とまったく同一な出力になることが保証されます。
</p></dd><dt id="APP-PSQL-OPTION-FIELD-SEPARATOR"><span class="term"><code class="option">-F <em class="replaceable"><code>separator</code></em></code><br /></span><span class="term"><code class="option">--field-separator=<em class="replaceable"><code>separator</code></em></code></span> <a href="#APP-PSQL-OPTION-FIELD-SEPARATOR" class="id_link">#</a></dt><dd><p>
<span class="original">
Use <replaceable class="parameter">separator</replaceable> as the
field separator for unaligned output. This is equivalent to
<command>\pset fieldsep</command> or <command>\f</command>.
</span>
<em class="replaceable"><code>separator</code></em>を位置揃えを行わない出力におけるフィールド区切り文字として使用します。
<code class="command">\pset fieldsep</code>もしくは<code class="command">\f</code>と同じ効力を持ちます。
</p></dd><dt id="APP-PSQL-OPTION-FIELD-HOST"><span class="term"><code class="option">-h <em class="replaceable"><code>hostname</code></em></code><br /></span><span class="term"><code class="option">--host=<em class="replaceable"><code>hostname</code></em></code></span> <a href="#APP-PSQL-OPTION-FIELD-HOST" class="id_link">#</a></dt><dd><p>
<span class="original">
Specifies the host name of the machine on which the
server is running. If the value begins
with a slash, it is used as the directory for the Unix-domain
socket.
</span>
サーバが稼働しているマシンのホスト名を指定します。
この値がスラッシュから始まる場合、Unixドメインソケット用のディレクトリとして使用されます。
</p></dd><dt id="APP-PSQL-OPTION-HTML"><span class="term"><code class="option">-H</code><br /></span><span class="term"><code class="option">--html</code></span> <a href="#APP-PSQL-OPTION-HTML" class="id_link">#</a></dt><dd><p>
<span class="original">
Switches to <acronym>HTML</acronym> output mode. This is
equivalent to <command>\pset format html</command> or the
<command>\H</command> command.
</span>
<acronym class="acronym">HTML</acronym>出力モードに切り替えます。
これは、<code class="command">\pset format html</code>もしくは<code class="command">\H</code>コマンドと同等です。
</p></dd><dt id="APP-PSQL-OPTION-LIST"><span class="term"><code class="option">-l</code><br /></span><span class="term"><code class="option">--list</code></span> <a href="#APP-PSQL-OPTION-LIST" class="id_link">#</a></dt><dd><p>
<span class="original">
List all available databases, then exit. Other non-connection
options are ignored. This is similar to the meta-command
<command>\list</command>.
</span>
利用可能な全てのデータベースを一覧表示し、終了します。
この他の接続に関連しないオプションは無視されます。
<code class="command">\list</code>メタコマンドと似た効力を持ちます。
</p><p>
<span class="original">
When this option is used, <application>psql</application> will connect
to the database <literal>postgres</literal>, unless a different database
is named on the command line (option <option>-d</option> or non-option
argument, possibly via a service entry, but not via an environment
variable).
</span>
このオプションが使用されるときは、別のデータベース名がコマンドラインで指定されない限り(オプション<code class="option">-d</code>または、環境変数ではない非オプション引数、おそらくサービスエントリを通じて)、<span class="application">psql</span>は、<code class="literal">postgres</code>データベースに接続します。
</p></dd><dt id="APP-PSQL-OPTION-LOG-FILE"><span class="term"><code class="option">-L <em class="replaceable"><code>filename</code></em></code><br /></span><span class="term"><code class="option">--log-file=<em class="replaceable"><code>filename</code></em></code></span> <a href="#APP-PSQL-OPTION-LOG-FILE" class="id_link">#</a></dt><dd><p>
<span class="original">
Write all query output into file <replaceable
class="parameter">filename</replaceable>, in addition to the
normal output destination.
</span>
すべての問い合わせの出力を通常の出力先に出力し、さらにファイル<em class="replaceable"><code>filename</code></em>に書き出します。
</p></dd><dt id="APP-PSQL-OPTION-NO-READLINE"><span class="term"><code class="option">-n</code><br /></span><span class="term"><code class="option">--no-readline</code></span> <a href="#APP-PSQL-OPTION-NO-READLINE" class="id_link">#</a></dt><dd><p>
<span class="original">
Do not use <application>Readline</application> for line editing and
do not use the command history (see
<xref linkend="app-psql-readline"/> below).
</span>
行編集とコマンド履歴に<span class="application">Readline</span>を使用しません(下記の<a class="xref" href="app-psql.html#APP-PSQL-READLINE" title="コマンドライン編集">「コマンドライン編集」</a>を参照)。
</p></dd><dt id="APP-PSQL-OPTION-OUTPUT"><span class="term"><code class="option">-o <em class="replaceable"><code>filename</code></em></code><br /></span><span class="term"><code class="option">--output=<em class="replaceable"><code>filename</code></em></code></span> <a href="#APP-PSQL-OPTION-OUTPUT" class="id_link">#</a></dt><dd><p>
<span class="original">
Put all query output into file <replaceable
class="parameter">filename</replaceable>. This is equivalent to
the command <command>\o</command>.
</span>
全ての問い合わせの出力を<em class="replaceable"><code>filename</code></em>ファイルに書き込みます。
これは<code class="command">\o</code>コマンドと同じ効力を持ちます。
</p></dd><dt id="APP-PSQL-OPTION-PORT"><span class="term"><code class="option">-p <em class="replaceable"><code>port</code></em></code><br /></span><span class="term"><code class="option">--port=<em class="replaceable"><code>port</code></em></code></span> <a href="#APP-PSQL-OPTION-PORT" class="id_link">#</a></dt><dd><p>
<span class="original">
Specifies the TCP port or the local Unix-domain
socket file extension on which the server is listening for
connections. Defaults to the value of the <envar>PGPORT</envar>
environment variable or, if not set, to the port specified at
compile time, usually 5432.
</span>
サーバが接続監視を行っているTCPポートもしくはローカルUnixドメインソケットファイルの拡張子を指定します。
環境変数<code class="envar">PGPORT</code>の値、環境変数が設定されていない場合はコンパイル時に指定した値(通常は5432)がデフォルト値となります。
</p></dd><dt id="APP-PSQL-OPTION-PSET"><span class="term"><code class="option">-P <em class="replaceable"><code>assignment</code></em></code><br /></span><span class="term"><code class="option">--pset=<em class="replaceable"><code>assignment</code></em></code></span> <a href="#APP-PSQL-OPTION-PSET" class="id_link">#</a></dt><dd><p>
<span class="original">
Specifies printing options, in the style of
<command>\pset</command>. Note that here you
have to separate name and value with an equal sign instead of a
space. For example, to set the output format to <application>LaTeX</application>, you could write
<literal>-P format=latex</literal>.
</span>
<code class="command">\pset</code>形式により表示オプションを指定します。
ここでは空白ではなく等号を使って名前と値を区切っていることに注意してください。
たとえば、出力形式を<span class="application">LaTeX</span>にする場合、<code class="literal">-P format=latex</code>と入力します。
</p></dd><dt id="APP-PSQL-OPTION-QUIET"><span class="term"><code class="option">-q</code><br /></span><span class="term"><code class="option">--quiet</code></span> <a href="#APP-PSQL-OPTION-QUIET" class="id_link">#</a></dt><dd><p>
<span class="original">
Specifies that <application>psql</application> should do its work
quietly. By default, it prints welcome messages and various
informational output. If this option is used, none of this
happens. This is useful with the <option>-c</option> option.
This is equivalent to setting the variable <varname>QUIET</varname>
to <literal>on</literal>.
</span>
<span class="application">psql</span>がメッセージ出力なしで処理を行うように指示します。
デフォルトでは、ウェルカム(welcome)メッセージや各種の情報が表示されます。
このオプションを使用すると、これらのメッセージが表示されません。
<code class="option">-c</code>オプションと併用すると便利です。
これは変数<code class="varname">QUIET</code>を<code class="literal">on</code>に設定するのと同じ効力を持ちます。
</p></dd><dt id="APP-PSQL-OPTION-RECORD-SEPARATOR"><span class="term"><code class="option">-R <em class="replaceable"><code>separator</code></em></code><br /></span><span class="term"><code class="option">--record-separator=<em class="replaceable"><code>separator</code></em></code></span> <a href="#APP-PSQL-OPTION-RECORD-SEPARATOR" class="id_link">#</a></dt><dd><p>
<span class="original">
Use <replaceable class="parameter">separator</replaceable> as the
record separator for unaligned output. This is equivalent to
<command>\pset recordsep</command>.
</span>
<em class="replaceable"><code>separator</code></em>を位置揃えを行わない出力におけるレコード区切り文字として使用します。
これは<code class="command">\pset recordsep</code>と同じです。
</p></dd><dt id="APP-PSQL-OPTION-SINGLE-STEP"><span class="term"><code class="option">-s</code><br /></span><span class="term"><code class="option">--single-step</code></span> <a href="#APP-PSQL-OPTION-SINGLE-STEP" class="id_link">#</a></dt><dd><p>
<span class="original">
Run in single-step mode. That means the user is prompted before
each command is sent to the server, with the option to cancel
execution as well. Use this to debug scripts.
</span>
シングルステップモードで実行します。
これは各コマンドがサーバに送信される前に、ユーザに対して実行するかキャンセルするかについて確認を求めることを意味します。
スクリプトのデバッグを行う時に使用してください。
</p></dd><dt id="APP-PSQL-OPTION-SINGLE-LINE"><span class="term"><code class="option">-S</code><br /></span><span class="term"><code class="option">--single-line</code></span> <a href="#APP-PSQL-OPTION-SINGLE-LINE" class="id_link">#</a></dt><dd><p>
<span class="original">
Runs in single-line mode where a newline terminates an SQL command, as a
semicolon does.
</span>
シングル行モードで実行します。このモードでは、セミコロンと同じように改行もSQLコマンドの終端として扱われます。
</p><div class="note"><h3 class="title">注記</h3><p>
<span class="original">
This mode is provided for those who insist on it, but you are not
necessarily encouraged to use it. In particular, if you mix
<acronym>SQL</acronym> and meta-commands on a line the order of
execution might not always be clear to the inexperienced user.
</span>
このモードはどうしてもこのような方式を使用したいユーザ向けに用意されたもので、必ずしも使用が推奨されるわけではありません。
特に、1行に<acronym class="acronym">SQL</acronym>とメタコマンドを混在させる場合、経験の浅いユーザにとってその実行順番は必ずしもわかりやすいものではありません。
</p></div></dd><dt id="APP-PSQL-OPTION-TUPLES-ONLY"><span class="term"><code class="option">-t</code><br /></span><span class="term"><code class="option">--tuples-only</code></span> <a href="#APP-PSQL-OPTION-TUPLES-ONLY" class="id_link">#</a></dt><dd><p>
<span class="original">
Turn off printing of column names and result row count footers,
etc. This is equivalent to <command>\t</command> or
<command>\pset tuples_only</command>.
</span>
列名と結果の行数フッタなどの表示を無効にします。
これは、<code class="command">\t</code>および<code class="command">\pset tuples_only</code>と同等です。
</p></dd><dt id="APP-PSQL-OPTION-TABLE-ATTR"><span class="term"><code class="option">-T <em class="replaceable"><code>table_options</code></em></code><br /></span><span class="term"><code class="option">--table-attr=<em class="replaceable"><code>table_options</code></em></code></span> <a href="#APP-PSQL-OPTION-TABLE-ATTR" class="id_link">#</a></dt><dd><p>
<span class="original">
Specifies options to be placed within the
<acronym>HTML</acronym> <sgmltag>table</sgmltag> tag. See
<command>\pset tableattr</command> for details.
</span>
<acronym class="acronym">HTML</acronym>の<code class="sgmltag-element">table</code>タグで使用されるオプションを指定します。
詳細は<code class="command">\pset tableattr</code>を参照してください。
</p></dd><dt id="APP-PSQL-OPTION-USERNAME"><span class="term"><code class="option">-U <em class="replaceable"><code>username</code></em></code><br /></span><span class="term"><code class="option">--username=<em class="replaceable"><code>username</code></em></code></span> <a href="#APP-PSQL-OPTION-USERNAME" class="id_link">#</a></dt><dd><p>
<span class="original">
Connect to the database as the user <replaceable
class="parameter">username</replaceable> instead of the default.
(You must have permission to do so, of course.)
</span>
デフォルトのユーザではなく<em class="replaceable"><code>username</code></em>ユーザとしてデータベースに接続します。
(当然、そうする権限を持っていなければなりません。)
</p></dd><dt id="APP-PSQL-OPTION-VARIABLE"><span class="term"><code class="option">-v <em class="replaceable"><code>assignment</code></em></code><br /></span><span class="term"><code class="option">--set=<em class="replaceable"><code>assignment</code></em></code><br /></span><span class="term"><code class="option">--variable=<em class="replaceable"><code>assignment</code></em></code></span> <a href="#APP-PSQL-OPTION-VARIABLE" class="id_link">#</a></dt><dd><p>
<span class="original">
Perform a variable assignment, like the <command>\set</command>
meta-command. Note that you must separate name and value, if
any, by an equal sign on the command line. To unset a variable,
leave off the equal sign. To set a variable with an empty value,
use the equal sign but leave off the value. These assignments are
done during command line processing, so variables that reflect
connection state will get overwritten later.
</span>
<code class="command">\set</code>メタコマンドのように、変数の代入を行います。
値がある場合、コマンドライン上では、名前と値を等号(=)で区切る必要があることに注意してください。
変数を未設定の状態にするには、等号を指定しないでください。
値が空の変数を設定するには、値を指定しないで等号のみ使用してください。
これらの代入はコマンドライン処理の段階で行われます。
そのため、接続状態を表す変数は後で上書きされる可能性があります。
</p></dd><dt id="APP-PSQL-OPTION-VERSION"><span class="term"><code class="option">-V</code><br /></span><span class="term"><code class="option">--version</code></span> <a href="#APP-PSQL-OPTION-VERSION" class="id_link">#</a></dt><dd><p>
<span class="original">
Print the <application>psql</application> version and exit.
</span>
<span class="application">psql</span>のバージョンを表示し、終了します。
</p></dd><dt id="APP-PSQL-OPTION-NO-PASSWORD"><span class="term"><code class="option">-w</code><br /></span><span class="term"><code class="option">--no-password</code></span> <a href="#APP-PSQL-OPTION-NO-PASSWORD" class="id_link">#</a></dt><dd><p>
<span class="original">
Never issue a password prompt. If the server requires password
authentication and a password is not available from other sources
such as a <filename>.pgpass</filename> file, the connection
attempt will fail. This option can be useful in batch jobs and
scripts where no user is present to enter a password.
</span>
パスワードの入力を促しません。
サーバがパスワード認証を必要とし、かつ、<code class="filename">.pgpass</code>ファイルなどの他の情報源からパスワードが入手可能でない場合、接続試行は失敗します。
バッチジョブやスクリプトなどパスワードを入力するユーザが存在しない場合にこのオプションは有用かもしれません。
</p><p>
<span class="original">
Note that this option will remain set for the entire session,
and so it affects uses of the meta-command
<command>\connect</command> as well as the initial connection attempt.
</span>
このオプションはセッション全体にわたって設定されたままであることに注意してください。
このため<code class="command">\connect</code>メタコマンドの使用に関しても初期接続試行と同様に影響します。
</p></dd><dt id="APP-PSQL-OPTION-PASSWORD"><span class="term"><code class="option">-W</code><br /></span><span class="term"><code class="option">--password</code></span> <a href="#APP-PSQL-OPTION-PASSWORD" class="id_link">#</a></dt><dd><p>
<span class="original">
Force <application>psql</application> to prompt for a
password before connecting to a database, even if the password will
not be used.
</span>
パスワードが使われない場合であっても、データベースに接続する前に<span class="application">psql</span>は強制的にパスワード入力を促します。
</p><p>
<span class="original">
If the server requires password authentication and a password is not
available from other sources such as a <filename>.pgpass</filename>
file, <application>psql</application> will prompt for a
password in any case. However, <application>psql</application>
will waste a connection attempt finding out that the server wants a
password. In some cases it is worth typing <option>-W</option> to avoid
the extra connection attempt.
</span>
サーバがパスワード認証を必要とし、かつ、<code class="filename">.pgpass</code>ファイルなどの他の情報源からパスワードが入手可能でない場合、<span class="application">psql</span>は常にパスワード入力を促します。
しかし、<span class="application">psql</span>は、サーバにパスワードが必要かどうかを判断するための接続試行を無駄に行います。
こうした余計な接続試行を防ぐために<code class="option">-W</code>の入力が有意となる場合もあります。
</p><p>
<span class="original">
Note that this option will remain set for the entire session,
and so it affects uses of the meta-command
<command>\connect</command> as well as the initial connection attempt.
</span>
このオプションはセッション全体に対して設定されたままであることに注意してください。
このため初期接続試行と同様に<code class="command">\connect</code>メタコマンドの使用にも影響を与えます。
</p></dd><dt id="APP-PSQL-OPTION-EXPANDED"><span class="term"><code class="option">-x</code><br /></span><span class="term"><code class="option">--expanded</code></span> <a href="#APP-PSQL-OPTION-EXPANDED" class="id_link">#</a></dt><dd><p>
<span class="original">
Turn on the expanded table formatting mode. This is equivalent to
<command>\x</command> or <command>\pset expanded</command>.
</span>
拡張テーブル形式モードを有効にします。
これは<code class="command">\x</code>および<code class="command">\pset expanded</code>と同じです。
</p></dd><dt id="APP-PSQL-OPTION-NO-PSQLRC"><span class="term"><code class="option">-X</code><br /></span><span class="term"><code class="option">--no-psqlrc</code></span> <a href="#APP-PSQL-OPTION-NO-PSQLRC" class="id_link">#</a></dt><dd><p>
<span class="original">
Do not read the start-up file (neither the system-wide
<filename>psqlrc</filename> file nor the user's
<filename>~/.psqlrc</filename> file).
</span>
起動用ファイル(<code class="filename">psqlrc</code>ファイルおよびユーザ用の<code class="filename">~/.psqlrc</code>ファイルのどちらも)を読み込みません。
</p></dd><dt id="APP-PSQL-OPTION-FIELD-SEPARATOR-ZERO"><span class="term"><code class="option">-z</code><br /></span><span class="term"><code class="option">--field-separator-zero</code></span> <a href="#APP-PSQL-OPTION-FIELD-SEPARATOR-ZERO" class="id_link">#</a></dt><dd><p>
<span class="original">
Set the field separator for unaligned output to a zero byte. This is
equivalent to <command>\pset fieldsep_zero</command>.
</span>
位置揃えを行わない出力用のフィールド区切り文字をゼロバイトに設定します。
これは<code class="command">\pset fieldsep_zero</code>と同じです。
</p></dd><dt id="APP-PSQL-OPTION-RECORD-SEPARATOR-ZERO"><span class="term"><code class="option">-0</code><br /></span><span class="term"><code class="option">--record-separator-zero</code></span> <a href="#APP-PSQL-OPTION-RECORD-SEPARATOR-ZERO" class="id_link">#</a></dt><dd><p>
<span class="original">
Set the record separator for unaligned output to a zero byte. This is
useful for interfacing, for example, with <literal>xargs -0</literal>.
This is equivalent to <command>\pset recordsep_zero</command>.
</span>
位置揃えを行わない出力用のレコード区切り文字をゼロバイトに設定します。
これは例えば<code class="literal">xargs -0</code>と連携する時に有用です。
これは<code class="command">\pset recordsep_zero</code>と同じです。
</p></dd><dt id="APP-PSQL-OPTION-SINGLE-TRANSACTION"><span class="term"><code class="option">-1</code><br /></span><span class="term"><code class="option">--single-transaction</code></span> <a href="#APP-PSQL-OPTION-SINGLE-TRANSACTION" class="id_link">#</a></dt><dd><p>
<span class="original">
This option can only be used in combination with one or more
<option>-c</option> and/or <option>-f</option> options. It causes
<application>psql</application> to issue a <command>BEGIN</command> command
before the first such option and a <command>COMMIT</command> command after
the last one, thereby wrapping all the commands into a single
transaction. If any of the commands fails and the variable
<varname>ON_ERROR_STOP</varname> was set, a
<command>ROLLBACK</command> command is sent instead. This ensures that
either all the commands complete successfully, or no changes are
applied.
</span>
このオプションは、1つ以上の<code class="option">-c</code>オプションや<code class="option">-f</code>オプションと組み合わせてのみ使うことができます。
これにより<span class="application">psql</span>は、最初のそのようなオプションの前に<code class="command">BEGIN</code>コマンドを発行し、最後のオプションの後に<code class="command">COMMIT</code>コマンドを発行するようになります。
そうすることで、すべてのコマンドが単一のトランザクションに囲まれます。
コマンドのいずれかが失敗して、変数<code class="varname">ON_ERROR_STOP</code>が設定されていれば、<code class="command">ROLLBACK</code>が代わりに送られます。
これによりすべてのコマンドが成功して完了するか、変更がまったく行われないかのいずれかになります。
</p><p>
<span class="original">
If the commands themselves
contain <command>BEGIN</command>, <command>COMMIT</command>,
or <command>ROLLBACK</command>, this option will not have the desired
effects. Also, if an individual command cannot be executed inside a
transaction block, specifying this option will cause the whole
transaction to fail.
</span>
コマンド自体が<code class="command">BEGIN</code>、<code class="command">COMMIT</code>、<code class="command">ROLLBACK</code>を含んでいる場合、このオプションは期待した効果を得ることができません。
また、個別のコマンドがトランザクションブロック内部で実行できない場合、このオプションを指定することで、そのトランザクション全体が失敗します。
</p></dd><dt id="APP-PSQL-OPTION-HELP"><span class="term"><code class="option">-?</code><br /></span><span class="term"><code class="option">--help[=<em class="replaceable"><code>topic</code></em>]</code></span> <a href="#APP-PSQL-OPTION-HELP" class="id_link">#</a></dt><dd><p>
<span class="original">
Show help about <application>psql</application> and exit. The optional
<replaceable class="parameter">topic</replaceable> parameter (defaulting
to <literal>options</literal>) selects which part of <application>psql</application> is
explained: <literal>commands</literal> describes <application>psql</application>'s
backslash commands; <literal>options</literal> describes the command-line
options that can be passed to <application>psql</application>;
and <literal>variables</literal> shows help about <application>psql</application> configuration
variables.
</span>
<span class="application">psql</span>に関するヘルプを表示し、終了します。
オプションの<em class="replaceable"><code>topic</code></em>パラメータ(デフォルトは<code class="literal">options</code>)は<span class="application">psql</span>のどの部分を説明するかを選択します。
<code class="literal">commands</code>は<span class="application">psql</span>のバックスラッシュコマンドについて、<code class="literal">options</code>は<span class="application">psql</span>に渡すことができるコマンドラインオプションについて、<code class="literal">variables</code>は<span class="application">psql</span>の設定変数についてのヘルプを表示します。
</p></dd></dl></div></div><div class="refsect1" id="id-1.9.4.21.7"><h2>終了ステータス</h2><span class="original">
<title>Exit Status</title>
</span><p>
<span class="original">
<application>psql</application> returns 0 to the shell if it
finished normally, 1 if a fatal error of its own occurs (e.g., out of memory,
file not found), 2 if the connection to the server went bad
and the session was not interactive, and 3 if an error occurred in a
script and the variable <varname>ON_ERROR_STOP</varname> was set.
</span>
<span class="application">psql</span>は、正常に終了した時には0を、<span class="application">psql</span>にとって致命的なエラー(メモリ不足やファイルが見つからないなど)が発生した時には1を、セッションが対話式でない状態でサーバとの接続が不完全になった時には2を、<code class="varname">ON_ERROR_STOP</code>変数が設定されている状態でスクリプトでエラーが発生した時には3をシェルに返します。
</p></div><div class="refsect1" id="id-1.9.4.21.8"><h2>使用方法</h2><span class="original">
<title>Usage</title>
</span><div class="refsect2" id="R2-APP-PSQL-CONNECTING"><h3>データベースへの接続</h3><span class="original">
<title>Connecting to a Database</title>
</span><p>
<span class="original">
<application>psql</application> is a regular
<productname>PostgreSQL</productname> client application. In order
to connect to a database you need to know the name of your target
database, the host name and port number of the server, and what
database user name you want to connect as. <application>psql</application>
can be told about those parameters via command line options, namely
<option>-d</option>, <option>-h</option>, <option>-p</option>, and
<option>-U</option> respectively. If an argument is found that does
not belong to any option it will be interpreted as the database name
(or the database user name, if the database name is already given). Not all
of these options are required; there are useful defaults. If you omit the host
name, <application>psql</application> will connect via a Unix-domain socket
to a server on the local host, or via TCP/IP to <literal>localhost</literal> on
Windows. The default port number is
determined at compile time.
Since the database server uses the same default, you will not have
to specify the port in most cases. The default database user name is your
operating-system user name. Once the database user name is determined, it
is used as the default database name.
Note that you cannot
just connect to any database under any database user name. Your database
administrator should have informed you about your access rights.
</span>
<span class="application">psql</span>は<span class="productname">PostgreSQL</span>の正式なクライアントアプリケーションです。
データベースに接続するには、接続するデータベース名、ホスト名、サーバのポート番号、接続する際に使用するデータベースユーザ名がわかっていなければなりません。
<span class="application">psql</span>では、それらをコマンドラインオプションで指定することができます。接続するデータベース名は<code class="option">-d</code>、ホスト名は<code class="option">-h</code>、サーバのポート番号は<code class="option">-p</code>、接続するユーザ名は<code class="option">-U</code>を使用してそれぞれ指定します。
オプションでない引数がある場合、それはデータベース名(データベース名が与えられている場合にはデータベースユーザ名)とみなされます。
これらのオプションは全て指定されている必要はありません。便利なデフォルト値があります。
ホスト名を省略した場合、<span class="application">psql</span>はUnixドメインソケット経由でローカルホスト上のサーバに、Windowsでは<code class="literal">localhost</code>にTCP/IP経由で接続します。
デフォルトのポート番号はコンパイル時に設定されます。
データベースサーバは同じデフォルト値を使用するので、多くの場合、ポートは指定する必要はありません。
デフォルトのデータベースユーザ名はOSのユーザ名です。
データベースユーザ名が決まれば、デフォルトのデータベース名として使われます。
任意のデータベースユーザ名で全てのデータベースに接続できるわけではないことに注意してください。
データベース管理者は、接続権限をユーザに知らせておかなければなりません。
</p><p>
<span class="original">
When the defaults aren't quite right, you can save yourself
some typing by setting the environment variables
<envar>PGDATABASE</envar>, <envar>PGHOST</envar>,
<envar>PGPORT</envar> and/or <envar>PGUSER</envar> to appropriate
values. (For additional environment variables, see <xref
linkend="libpq-envars"/>.) It is also convenient to have a
<filename>~/.pgpass</filename> file to avoid regularly having to type in
passwords. See <xref linkend="libpq-pgpass"/> for more information.
</span>
デフォルトが完全には適用できない時は、入力の手間を省くために、環境変数<code class="envar">PGDATABASE</code>、<code class="envar">PGHOST</code>、<code class="envar">PGPORT</code>、<code class="envar">PGUSER</code>に適当な値を設定することもできます。
(この他の環境変数については、<a class="xref" href="libpq-envars.html" title="32.15. 環境変数">32.15</a>を参照してください。)
また、<code class="filename">~/.pgpass</code>ファイルを使用すれば、定常的なパスワードの入力を省略でき、便利です。
詳細は<a class="xref" href="libpq-pgpass.html" title="32.16. パスワードファイル">32.16</a>を参照してください。
</p><p>
<span class="original">
An alternative way to specify connection parameters is in a
<parameter>conninfo</parameter> string or
a <acronym>URI</acronym>, which is used instead of a database
name. This mechanism give you very wide control over the
connection. For example:
</span>
他の接続パラメータの指定方法として<em class="parameter"><code>conninfo</code></em>文字列または<acronym class="acronym">URI</acronym>があります。
これは、データベース名の代わりに使用されます。
この機構により、接続全体に関する非常に幅広い制御を行うことができます。
以下に例を示します。
</p><pre class="programlisting">
$ <strong class="userinput"><code>psql "service=myservice sslmode=require"</code></strong>
$ <strong class="userinput"><code>psql postgresql://dbmaster:5433/mydb?sslmode=require</code></strong>
</pre><p>
<span class="original">
This way you can also use <acronym>LDAP</acronym> for connection
parameter lookup as described in <xref linkend="libpq-ldap"/>.
See <xref linkend="libpq-paramkeywords"/> for more information on all the
available connection options.
</span>
この方法では接続パラメータの検索に、<a class="xref" href="libpq-ldap.html" title="32.18. 接続パラメータのLDAP検索">32.18</a>で説明する<acronym class="acronym">LDAP</acronym>を使用することもできます。
利用できる接続オプションのすべてについての詳細は、<a class="xref" href="libpq-connect.html#LIBPQ-PARAMKEYWORDS" title="32.1.2. パラメータキーワード">32.1.2</a>を参照してください。
</p><p>
<span class="original">
If the connection could not be made for any reason (e.g., insufficient
privileges, server is not running on the targeted host, etc.),
<application>psql</application> will return an error and terminate.
</span>
何らかの原因(権限がない、指定したホストでサーバが稼働していないなど)で接続ができなかった場合は、<span class="application">psql</span>はエラーメッセージを表示し、終了します。
</p><p>
<span class="original">
If both standard input and standard output are a
terminal, then <application>psql</application> sets the client
encoding to <quote>auto</quote>, which will detect the
appropriate client encoding from the locale settings
(<envar>LC_CTYPE</envar> environment variable on Unix systems).
If this doesn't work out as expected, the client encoding can be
overridden using the environment
variable <envar>PGCLIENTENCODING</envar>.
</span>
標準入力および標準出力の両方が端末である場合、<span class="application">psql</span>はクライアントの符号化方式を<span class="quote">「<span class="quote">auto</span>」</span>に設定します。
これはロケール設定(Unixシステムでは環境変数<code class="envar">LC_CTYPE</code>)から適切なクライアント符号化方式を決定します。
想定した通りに動作しない場合、環境変数<code class="envar">PGCLIENTENCODING</code>を使用してクライアント符号化方式を上書きすることができます。
</p></div><div class="refsect2" id="R2-APP-PSQL-4"><h3>SQLコマンドの入力</h3><span class="original">
<title>Entering SQL Commands</title>
</span><p>
<span class="original">
In normal operation, <application>psql</application> provides a
prompt with the name of the database to which
<application>psql</application> is currently connected, followed by
the string <literal>=&gt;</literal>. For example:
</span>
通常の操作において、<span class="application">psql</span>は、<span class="application">psql</span>が現在接続しているデータベース名の後に<code class="literal">=></code>の文字列が付いたプロンプトを表示します。
以下に例を示します。
</p><pre class="programlisting">
$ <strong class="userinput"><code>psql testdb</code></strong>
psql (18.3)
Type "help" for help.
testdb=>
</pre><p>
</p><p>
<span class="original">
At the prompt, the user can type in <acronym>SQL</acronym> commands.
Ordinarily, input lines are sent to the server when a
command-terminating semicolon is reached. An end of line does not
terminate a command. Thus commands can be spread over several lines for
clarity. If the command was sent and executed without error, the results
of the command are displayed on the screen.
</span>
プロンプトに対しユーザは<acronym class="acronym">SQL</acronym>コマンドを入力することができます。
通常、入力された行はコマンド終了を意味するセミコロンに達した時点でサーバへと送信されます。
改行はコマンドの終了とはみなされません。
したがって、わかりやすくするために、コマンドは複数の行にわたって記述することができます。
コマンドが送信され問題なく実行されると、画面にコマンドの結果が表示されます。
</p><p>
<span class="original">
If untrusted users have access to a database that has not adopted a
<link linkend="ddl-schemas-patterns">secure schema usage pattern</link>,
begin your session by removing publicly-writable schemas
from <varname>search_path</varname>. One can
add <literal>options=-csearch_path=</literal> to the connection string or
issue <literal>SELECT pg_catalog.set_config('search_path', '',
false)</literal> before other SQL commands. This consideration is not
specific to <application>psql</application>; it applies to every interface
for executing arbitrary SQL commands.
</span>
<a class="link" href="ddl-schemas.html#DDL-SCHEMAS-PATTERNS" title="5.10.6. 使用パターン">安全なスキーマの利用パターン</a>を適用していないデータベースに信頼できないユーザがアクセス可能な場合は、セッションの開始時に<code class="varname">search_path</code>から、誰でも書き込みができるスキーマを削除してください。
<code class="literal">options=-csearch_path=</code>を接続文字列に追加するか、<code class="literal">SELECT pg_catalog.set_config('search_path', '', false)</code>を他のSQLの前に発行することができます。
この配慮は<span class="application">psql</span>に固有のものではありません。
任意のSQLを実行するすべてのインタフェースに適用されるものです。
</p><p>
<span class="original">
Whenever a command is executed, <application>psql</application> also polls
for asynchronous notification events generated by
<link linkend="sql-listen"><command>LISTEN</command></link> and
<link linkend="sql-notify"><command>NOTIFY</command></link>.
</span>
また、コマンドが実行される度に、<span class="application">psql</span>は<a class="link" href="sql-listen.html" title="LISTEN"><code class="command">LISTEN</code></a>と<a class="link" href="sql-notify.html" title="NOTIFY"><code class="command">NOTIFY</code></a>によって生成された非同期通知イベントを検査します。
</p><p>
<span class="original">
While C-style block comments are passed to the server for
processing and removal, SQL-standard comments are removed by
<application>psql</application>.
</span>
Cの形式のブロックコメントは、サーバに送信され、サーバによって取り除かれますが、標準SQLのコメントは<span class="application">psql</span>によって取り除かれます。
</p></div><div class="refsect2" id="APP-PSQL-META-COMMANDS"><h3>メタコマンド</h3><span class="original">
<title>Meta-Commands</title>
</span><p>
<span class="original">
Anything you enter in <application>psql</application> that begins
with an unquoted backslash is a <application>psql</application>
meta-command that is processed by <application>psql</application>
itself. These commands make
<application>psql</application> more useful for administration or
scripting. Meta-commands are often called slash or backslash commands.
</span>
<span class="application">psql</span>内で入力されたコマンドのうち、引用符で囲まれていないバックスラッシュで始まるものは、<span class="application">psql</span>自身が実行する<span class="application">psql</span>のメタコマンドとして扱われます。
これらのコマンドを使うと、データベースを管理したりスクリプトを作成するにあたって、<span class="application">psql</span>がより便利になります。
メタコマンドはよくスラッシュコマンド、またはバックスラッシュコマンドとも呼ばれます。
</p><p>
<span class="original">
The format of a <application>psql</application> command is the backslash,
followed immediately by a command verb, then any arguments. The arguments
are separated from the command verb and each other by any number of
whitespace characters.
</span>
<span class="application">psql</span>コマンドは、バックスラッシュ、コマンド本体、引数の順につなげた形式になっています。
引数とコマンド本体の間および引数と引数の間は、空白文字によって分割されています。
</p><p>
<span class="original">
To include whitespace in an argument you can quote it with
single quotes. To include a single quote in an argument,
write two single quotes within single-quoted text.
Anything contained in single quotes is
furthermore subject to C-like substitutions for
<literal>\n</literal> (new line), <literal>\t</literal> (tab),
<literal>\b</literal> (backspace), <literal>\r</literal> (carriage return),
<literal>\f</literal> (form feed),
<literal>\</literal><replaceable>digits</replaceable> (octal), and
<literal>\x</literal><replaceable>digits</replaceable> (hexadecimal).
A backslash preceding any other character within single-quoted text
quotes that single character, whatever it is.
</span>
引数に空白を含める場合は単一引用符で囲みます。
単一引用符を引数に含める場合には、単一引用符で括られた文字列の中で、その単一引用符を2つ続けてください。
単一引用符で囲われた文字は、C言語と同じような置換の対象となります。
このような文字には、<code class="literal">\n</code>(改行)、<code class="literal">\t</code>(タブ)、<code class="literal">\b</code> (後退)、<code class="literal">\r</code>(復帰)、<code class="literal">\f</code> (改頁)、<code class="literal">\</code><em class="replaceable"><code>digits</code></em>(8進数で表された文字)、<code class="literal">\x</code><em class="replaceable"><code>digits</code></em>(16進数で表された文字)があります。
単一引用符で括られたテキスト内でその他の任意の文字の前にバックスラッシュを付けた場合は、その文字が何であろうとその一文字だけとして扱われます。
</p><p>
<span class="original">
If an unquoted colon (<literal>:</literal>) followed by a
<application>psql</application> variable name appears within an argument, it is
replaced by the variable's value, as described in <xref
linkend="app-psql-interpolation"/> below.
The forms <literal>:'<replaceable>variable_name</replaceable>'</literal> and
<literal>:"<replaceable>variable_name</replaceable>"</literal> described there
work as well.
The <literal>:{?<replaceable>variable_name</replaceable>}</literal> syntax allows
testing whether a variable is defined. It is substituted by
TRUE or FALSE.
Escaping the colon with a backslash protects it from substitution.
</span>
<a class="xref" href="app-psql.html#APP-PSQL-INTERPOLATION" title="SQL差し替え">SQL差し替え</a>で説明されているとおり、引数の中に引用符で囲まれていないコロン(<code class="literal">:</code>)とそれに続く<span class="application">psql</span>変数がある場合、その部分は変数の値で置換されます。
そこで説明されている<code class="literal">:'<em class="replaceable"><code>variable_name</code></em>'</code>および<code class="literal">:"<em class="replaceable"><code>variable_name</code></em>"</code>という形式も同様に機能します。
<code class="literal">:{?<em class="replaceable"><code>variable_name</code></em>}</code>構文は、変数が定義済みかどうかをテストできます。
これはTRUEかFALSEに置き換えられます。
コロンをバックスラッシュでエスケープすると置換が防止されます。
</p><p>
<span class="original">
Within an argument, text that is enclosed in backquotes
(<literal>`</literal>) is taken as a command line that is passed to the
shell. The output of the command (with any trailing newline removed)
replaces the backquoted text. Within the text enclosed in backquotes,
no special quoting or other processing occurs, except that appearances
of <literal>:<replaceable>variable_name</replaceable></literal> where
<replaceable>variable_name</replaceable> is a <application>psql</application> variable name
are replaced by the variable's value. Also, appearances of
<literal>:'<replaceable>variable_name</replaceable>'</literal> are replaced by the
variable's value suitably quoted to become a single shell command
argument. (The latter form is almost always preferable, unless you are
very sure of what is in the variable.) Because carriage return and line
feed characters cannot be safely quoted on all platforms, the
<literal>:'<replaceable>variable_name</replaceable>'</literal> form prints an
error message and does not substitute the variable value when such
characters appear in the value.
</span>
引数の中で逆引用符(<code class="literal">`</code>)に囲まれた文字列は、シェルに渡されるコマンドラインとして解釈されます。
逆引用符に囲まれた文字列は、コマンドの出力(行末の改行はすべて削除されます)で置換されます。
逆引用符に囲まれた文字列内では、<code class="literal">:<em class="replaceable"><code>variable_name</code></em></code>という形式で<em class="replaceable"><code>variable_name</code></em>が<span class="application">psql</span>の変数名であるものが、その変数の値で置換されることを除いて、特別な引用やその他の処理は起きません。
また<code class="literal">:'<em class="replaceable"><code>variable_name</code></em>'</code>という形式なら、それが変数値で置換された上で、それがシェルコマンドの単一の引数となるよう適切に引用符が付けられます。
(変数に何が入っているのか正確に理解しているのでなければ、ほとんどすべての場合で後者の形式の方が望ましいでしょう。)
復帰文字、改行文字をすべてのプラットフォームで安全に引用することはできないので、そのような文字が変数値に含まれていた場合は、<code class="literal">:'<em class="replaceable"><code>variable_name</code></em>'</code>はエラーメッセージを表示し、変数値による置換を行いません。
</p><p>
<span class="original">
Some commands take an <acronym>SQL</acronym> identifier (such as a
table name) as argument. These arguments follow the syntax rules
of <acronym>SQL</acronym>: Unquoted letters are forced to
lowercase, while double quotes (<literal>"</literal>) protect letters
from case conversion and allow incorporation of whitespace into
the identifier. Within double quotes, paired double quotes reduce
to a single double quote in the resulting name. For example,
<literal>FOO"BAR"BAZ</literal> is interpreted as <literal>fooBARbaz</literal>,
and <literal>"A weird"" name"</literal> becomes <literal>A weird"
name</literal>.
</span>
コマンドには、引数として(テーブル名などの)<acronym class="acronym">SQL</acronym>の識別子を取るものがあります。
これらの引数は次のような<acronym class="acronym">SQL</acronym>の構文規則に従います。
引用符を伴わない文字は強制的に小文字になります。しかし、二重引用符(<code class="literal">"</code>)で囲まれると、大文字小文字変換が行われず、空白文字を識別子内に含めることができます。
さらに、二重引用符内では、連続する2つの二重引用符は1つの二重引用符とみなされます。
例えば、<code class="literal">FOO"BAR"BAZ</code>は<code class="literal">fooBARbaz</code>と解釈され、<code class="literal">"A weird"" name"</code>は<code class="literal">A weird" name</code>になります。
</p><p>
<span class="original">
Parsing for arguments stops at the end of the line, or when another
unquoted backslash is found. An unquoted backslash
is taken as the beginning of a new meta-command. The special
sequence <literal>\\</literal> (two backslashes) marks the end of
arguments and continues parsing <acronym>SQL</acronym> commands, if
any. That way <acronym>SQL</acronym> and
<application>psql</application> commands can be freely mixed on a
line. But in any case, the arguments of a meta-command cannot
continue beyond the end of the line.
</span>
引数の解析は行末または引用符で囲まれていないもう1つのバックスラッシュが見つかると終了します。
引用符がないバックスラッシュは新しいメタコマンドの始まりと解釈されます。
<code class="literal">\\</code>(バックスラッシュ2つ)という特別な文字の並びは引数の終わりを意味するので、<acronym class="acronym">SQL</acronym>コマンドが残されている場合は、その解析を続けます。
このように、<acronym class="acronym">SQL</acronym>コマンドと<span class="application">psql</span>コマンドは1つの行に自由に混合して記述することができます。
しかし、あらゆる場合において、メタコマンドの引数は行をまたぐことはできません。
</p><p>
<span class="original">
Many of the meta-commands act on the <firstterm>current query buffer</firstterm>.
This is simply a buffer holding whatever SQL command text has been typed
but not yet sent to the server for execution. This will include previous
input lines as well as any text appearing before the meta-command on the
same line.
</span>
メタコマンドの多くは<em class="firstterm">問い合わせバッファ</em>の上で動作します。
これは入力されたSQLコマンド文字列で、まだ実行のためにサーバに送信されていないものをすべて保持するだけのバッファです。
これには以前の入力行や、同じ行のメタコマンドより前に入力されたすべての文字列も含まれます。
</p><p>
<span class="original">
Many of the meta-commands also allow <literal>x</literal> to be appended
as an option. This will cause the results to be displayed in expanded
mode, as if <command>\x</command> or <command>\pset expanded</command>
had been used.
</span>
多くのメタコマンドでは、オプションとして<code class="literal">x</code>を付与することもできます。
これにより、<code class="command">\x</code>や<code class="command">\pset expanded</code>が使用されたかのように、拡張モードで結果が表示されます。
</p><p>
<span class="original">
The following meta-commands are defined:
</span>
以下のメタコマンドが定義されています。
</p><div class="variablelist"><dl class="variablelist"><dt id="APP-PSQL-META-COMMAND-A"><span class="term"><code class="literal">\a</code></span> <a href="#APP-PSQL-META-COMMAND-A" class="id_link">#</a></dt><dd><p>
<span class="original">
If the current table output format is unaligned, it is switched to aligned.
If it is not unaligned, it is set to unaligned. This command is
kept for backwards compatibility. See <command>\pset</command> for a
more general solution.
</span>
現在のテーブルの出力形式が「揃えない」になっていれば「揃える」に切り替えます。
「揃える」になっていれば「揃えない」に設定します。
このコマンドは後方互換性を保持するためにあります。
より一般的な解決策は<code class="command">\pset</code>を参照してください。
</p></dd><dt id="APP-PSQL-META-COMMAND-BIND"><span class="term"><code class="literal">\bind</code> [ <em class="replaceable"><code>parameter</code></em> ] ... </span> <a href="#APP-PSQL-META-COMMAND-BIND" class="id_link">#</a></dt><dd><p>
<span class="original">
Sets query parameters for the next query execution, with the
specified parameters passed for any parameter placeholders
(<literal>$1</literal> etc.).
</span>
次の問い合わせ実行の問い合わせパラメータを設定します。指定されたパラメータはすべてのパラメータプレースホルダ(<code class="literal">$1</code>など)に渡されます。
</p><p>
<span class="original">
Example:
</span>
例:
</p><pre class="programlisting">
INSERT INTO tbl1 VALUES ($1, $2) \bind 'first value' 'second value' \g
</pre><p>
</p><p>
<span class="original">
This also works for query-execution commands besides
<literal>\g</literal>, such as <literal>\gx</literal> and
<literal>\gset</literal>.
</span>
これは、<code class="literal">\gx</code>や<code class="literal">\gset</code>のような、<code class="literal">\g</code>以外の問い合わせ実行コマンドにも有効です。
</p><p>
<span class="original">
This command causes the extended query protocol (see <xref
linkend="protocol-query-concepts"/>) to be used, unlike normal
<application>psql</application> operation, which uses the simple
query protocol. So this command can be useful to test the extended
query protocol from <application>psql</application>. (The extended
query protocol is used even if the query has no parameters and this
command specifies zero parameters.) This command affects only the
next query executed; all subsequent queries will use the simple query
protocol by default.
</span>
このコマンドは、通常の<span class="application">psql</span>操作とは異なり、拡張問い合わせプロトコル(<a class="xref" href="protocol-overview.html#PROTOCOL-QUERY-CONCEPTS" title="54.1.2. 拡張問い合わせの概要">54.1.2</a>を参照)を使用します。
通常は、簡易問い合わせプロトコルを使用します。
したがって、このコマンドは、<span class="application">psql</span>から拡張問い合わせプロトコルをテストするのに有用でしょう。
(拡張問い合わせプロトコルは、問い合わせにパラメータがなく、このコマンドがパラメータを指定していない場合でも使用されます。)
このコマンドは、次に実行される問い合わせにのみ影響します。
後続のすべての問い合わせは、デフォルトで簡易問い合わせプロトコルを使用します。
</p></dd><dt id="APP-PSQL-META-COMMAND-BIND-NAMED"><span class="term"><code class="literal">\bind_named</code> <em class="replaceable"><code>statement_name</code></em> [ <em class="replaceable"><code>parameter</code></em> ] ... </span> <a href="#APP-PSQL-META-COMMAND-BIND-NAMED" class="id_link">#</a></dt><dd><p>
<span class="original">
<literal>\bind_named</literal> is equivalent to <literal>\bind</literal>,
except that it takes the name of an existing prepared statement as
first parameter. An empty string denotes the unnamed prepared
statement.
</span>
<code class="literal">\bind_named</code>は<code class="literal">\bind</code>と同等ですが、既存のプリペアド文の名前を最初のパラメータとして使用する点が異なります。
空の文字列は、名前のないプリペアド文を示します。
</p><p>
<span class="original">
Example:
</span>
例:
</p><pre class="programlisting">
INSERT INTO tbls1 VALUES ($1, $2) \parse stmt1
\bind_named stmt1 'first value' 'second value' \g
</pre><p>
</p><p>
<span class="original">
This command causes the extended query protocol (see
<xref linkend="protocol-query-concepts"/>) to be used, unlike normal
<application>psql</application> operation, which uses the simple
query protocol. So this command can be useful to test the extended
query protocol from <application>psql</application>.
</span>
このコマンドは、通常の<span class="application">psql</span>操作とは異なり、拡張問い合わせプロトコル(<a class="xref" href="protocol-overview.html#PROTOCOL-QUERY-CONCEPTS" title="54.1.2. 拡張問い合わせの概要">54.1.2</a>を参照)を使用します。
通常は、簡易問い合わせプロトコルを使用します。
したがって、このコマンドは、<span class="application">psql</span>から拡張問い合わせプロトコルをテストするのに有用でしょう。
</p></dd><dt id="APP-PSQL-META-COMMAND-C-LC"><span class="term"><code class="literal">\c</code> または <code class="literal">\connect [ -reuse-previous=<em class="replaceable"><code>on|off</code></em> ] [ <em class="replaceable"><code>dbname</code></em> [ <em class="replaceable"><code>username</code></em> ] [ <em class="replaceable"><code>host</code></em> ] [ <em class="replaceable"><code>port</code></em> ] | <em class="replaceable"><code>conninfo</code></em> ]</code></span> <a href="#APP-PSQL-META-COMMAND-C-LC" class="id_link">#</a></dt><dd><p>
<span class="original">
Establishes a new connection to a <productname>PostgreSQL</productname>
server. The connection parameters to use can be specified either
using a positional syntax (one or more of database name, user,
host, and port), or using a <replaceable>conninfo</replaceable>
connection string as detailed in
<xref linkend="libpq-connstring"/>. If no arguments are given, a
new connection is made using the same parameters as before.
</span>
<span class="productname">PostgreSQL</span>サーバへの新規の接続を確立します。
接続のパラメータは、位置の構文(1つ以上のデータベース名、ユーザ、ホスト、ポート)、あるいは<em class="replaceable"><code>conninfo</code></em>接続文字列で指定できます。後者の詳細は<a class="xref" href="libpq-connect.html#LIBPQ-CONNSTRING" title="32.1.1. 接続文字列">32.1.1</a>で説明します。
引数が与えられなければ、新しい接続は以前と同じパラメータを使って作られます。
</p><p>
<span class="original">
Specifying any
of <replaceable class="parameter">dbname</replaceable>,
<replaceable class="parameter">username</replaceable>,
<replaceable class="parameter">host</replaceable> or
<replaceable class="parameter">port</replaceable>
as <literal>-</literal> is equivalent to omitting that parameter.
</span>
<em class="replaceable"><code>dbname</code></em>、<em class="replaceable"><code>username</code></em>、<em class="replaceable"><code>host</code></em>、<em class="replaceable"><code>port</code></em>のいずれについても<code class="literal">-</code>を指定するのは、パラメータを省略するのと同じになります。
</p><p>
<span class="original">
The new connection can re-use connection parameters from the previous
connection; not only database name, user, host, and port, but other
settings such as <replaceable>sslmode</replaceable>. By default,
parameters are re-used in the positional syntax, but not when
a <replaceable>conninfo</replaceable> string is given. Passing a
first argument of <literal>-reuse-previous=on</literal>
or <literal>-reuse-previous=off</literal> overrides that default. If
parameters are re-used, then any parameter not explicitly specified as
a positional parameter or in the <replaceable>conninfo</replaceable>
string is taken from the existing connection's parameters. An
exception is that if the <replaceable>host</replaceable> setting
is changed from its previous value using the positional syntax,
any <replaceable>hostaddr</replaceable> setting present in the
existing connection's parameters is dropped.
Also, any password used for the existing connection will be re-used
only if the user, host, and port settings are not changed.
When the command neither specifies nor reuses a particular parameter,
the <application>libpq</application> default is used.
</span>
新しい接続では以前の接続での接続パラメータを再利用できます。データベース名、ユーザ、ホスト、ポートだけでなく、<em class="replaceable"><code>sslmode</code></em>のようなその他の設定もです。
デフォルトでは、パラメータは位置の構文では再利用されますが、<em class="replaceable"><code>conninfo</code></em>文字列が与えられた場合はそうではありません。
第一引数で<code class="literal">-reuse-previous=on</code>あるいは<code class="literal">-reuse-previous=off</code>を渡すことで、このデフォルトと異なる動作をさせることができます。
パラメータが再利用される場合、位置パラメータとして明示的に指定されなかったパラメータや<em class="replaceable"><code>conninfo</code></em>文字列で指定されていないパラメータは、既存の接続のパラメータから取得されます。
例外は、<em class="replaceable"><code>host</code></em>設定が位置の構文を使った以前の値から変更された場合に、既存の接続のパラメータにある<em class="replaceable"><code>hostaddr</code></em>設定が削除されることです。
また、既存の接続で使われたパスワードは、ユーザ、ホスト、ポート設定が変更されていない場合にのみ再利用されます。
コマンドで特定のパラメータを指定せず、かつ再利用もしない場合は、<span class="application">libpq</span>のデフォルトが使用されます。
</p><p>
<span class="original">
If the new connection is successfully made, the previous
connection is closed.
If the connection attempt fails (wrong user name, access
denied, etc.), the previous connection will be kept if
<application>psql</application> is in interactive mode. But when
executing a non-interactive script, the old connection is closed
and an error is reported. That may or may not terminate the
script; if it does not, all database-accessing commands will fail
until another <literal>\connect</literal> command is successfully
executed. This distinction was chosen as
a user convenience against typos on the one hand, and a safety
mechanism that scripts are not accidentally acting on the
wrong database on the other hand.
Note that whenever a <literal>\connect</literal> command attempts
to re-use parameters, the values re-used are those of the last
successful connection, not of any failed attempts made subsequently.
However, in the case of a
non-interactive <literal>\connect</literal> failure, no parameters
are allowed to be re-used later, since the script would likely be
expecting the values from the failed <literal>\connect</literal>
to be re-used.
</span>
新規接続に成功した場合、以前の接続は閉じられます。
接続の試行が(ユーザ名の間違いやアクセス拒否などの理由で)失敗した場合、<span class="application">psql</span>が対話式モードである場合、それまでの接続が保持されます。
非対話式スクリプトを実行している場合は、古い接続は閉じられエラーが報告されます。
これはスクリプトを終了させるかもしれませんし、させないかもしれません。終了させない場合、別の<code class="literal">\connect</code>コマンドが実行に成功するまで、データベースにアクセスするコマンドはすべて失敗します。
この実装の違いは、対話モードでは入力ミスに対するユーザの利便性を考慮し、非対話モードではスクリプトによって間違ったデータベースを操作することを防ぐための安全策を考慮した結果決められました。
<code class="literal">\connect</code>コマンドがパラメータの再利用を試す場合には、再利用する値は必ず最後に接続に成功したものであり、その後で試して失敗したものではないことに注意してください。
しかしながら、非対話モードで<code class="literal">\connect</code>が失敗した場合には、スクリプトは失敗した<code class="literal">\connect</code>から再利用する値を得ようとしますので、パラメータを後で再利用できません。
</p><p>
<span class="original">
Examples:
</span>