This repository has been archived by the owner on Mar 31, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathClientUtilityReference.html
800 lines (724 loc) · 158 KB
/
ClientUtilityReference.html
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
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<!-- Always force latest IE rendering engine or request Chrome Frame -->
<meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible">
<!-- REPLACE X WITH PRODUCT NAME -->
<title>Client Utility Reference | Pivotal Docs</title>
<!-- Local CSS stylesheets -->
<link href="/stylesheets/master.css" media="screen,print" rel="stylesheet" type="text/css" />
<link href="/stylesheets/breadcrumbs.css" media="screen,print" rel="stylesheet" type="text/css" />
<link href="/stylesheets/search.css" media="screen,print" rel="stylesheet" type="text/css" />
<link href="/stylesheets/portal-style.css" media="screen,print" rel="stylesheet" type="text/css" />
<link href="/stylesheets/printable.css" media="print" rel="stylesheet" type="text/css" />
<!-- Confluence HTML stylesheet -->
<link href="/stylesheets/site-conf.css" media="screen,print" rel="stylesheet" type="text/css" />
<!-- Left-navigation code -->
<!-- http://www.designchemical.com/lab/jquery-vertical-accordion-menu-plugin/examples/# -->
<link href="/stylesheets/dcaccordion.css" rel="stylesheet" type="text/css" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script>
<script src="/javascripts/jquery.cookie.js" type="text/javascript"></script>
<script src="/javascripts/jquery.hoverIntent.minified.js" type="text/javascript"></script>
<script src="/javascripts/jquery.dcjqaccordion.2.7.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function($){
$('#accordion-1').dcAccordion({
eventType: 'click',
autoClose: true,
saveState: true,
disableLink: false,
speed: 'fast',
classActive: 'test',
showCount: false
});
});
</script>
<link href="/stylesheets/grey.css" rel="stylesheet" type="text/css" />
<!-- End left-navigation code -->
<script src="/javascripts/all.js" type="text/javascript"></script>
<link href='http://www.gopivotal.com/misc/favicon.ico' rel='shortcut icon'>
<script type="text/javascript">
if (window.location.host === 'docs.gopivotal.com') {
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-39702075-1']);
_gaq.push(['_setDomainName', 'gopivotal.com']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
}
</script>
</head>
<body class="pivotalcf pivotalcf_getstarted pivotalcf_getstarted_index">
<div class="viewport">
<div class="mobile-navigation--wrapper mobile-only">
<div class="navigation-drawer--container">
<div class="navigation-item-list">
<div class="navbar-link active">
<a href="http://gopivotal.com">
Home
<i class="icon-chevron-right pull-right"></i>
</a>
</div>
<div class="navbar-link">
<a href="http://gopivotal.com/paas">
PaaS
<i class="icon-chevron-right pull-right"></i>
</a>
</div>
<div class="navbar-link">
<a href="http://gopivotal.com/big-data">
Big Data
<i class="icon-chevron-right pull-right"></i>
</a>
</div>
<div class="navbar-link">
<a href="http://gopivotal.com/agile">
Agile
<i class="icon-chevron-right pull-right"></i>
</a>
</div>
<div class="navbar-link">
<a href="http://gopivotal.com/support">
Help & Support
<i class="icon-chevron-right pull-right"></i>
</a>
</div>
<div class="navbar-link">
<a href="http://gopivotal.com/products">
Products
<i class="icon-chevron-right pull-right"></i>
</a>
</div>
<div class="navbar-link">
<a href="http://gopivotal.com/solutions">
Solutions
<i class="icon-chevron-right pull-right"></i>
</a>
</div>
<div class="navbar-link">
<a href="http://gopivotal.com/partners">
Partners
<i class="icon-chevron-right pull-right"></i>
</a>
</div>
</div>
</div>
<div class="mobile-nav">
<div class="nav-icon js-open-nav-drawer">
<i class="icon-reorder"></i>
</div>
<div class="header-center-icon">
<a href="http://gopivotal.com">
<div class="icon icon-pivotal-logo-mobile"></div>
</a>
</div>
</div>
</div>
<div class='wrap'>
<script src="//use.typekit.net/clb0qji.js" type="text/javascript"></script>
<script type="text/javascript">
try {
Typekit.load();
} catch (e) {
}
</script>
<script type="text/javascript">
document.domain = "gopivotal.com";
</script>
<script type="text/javascript">
WebFontConfig = {
google: { families: [ 'Source+Sans+Pro:300italic,400italic,600italic,300,400,600:latin' ] }
};
(function() {
var wf = document.createElement('script');
wf.src = ('https:' == document.location.protocol ? 'https' : 'http') +
'://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js';
wf.type = 'text/javascript';
wf.async = 'true';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(wf, s);
})(); </script>
<div id="search-dropdown-box">
<div class="search-dropdown--container js-search-dropdown">
<div class="container-fluid">
<div class="close-menu-large"><img src="http://www.gopivotal.com/sites/all/themes/gopo13/images/icon-close.png" /></div>
<div class="search-form--container">
<div class="form-search">
<div class='gcse-search'></div>
<script src="http://www.google.com/jsapi" type="text/javascript"></script>
<script src="/javascripts/cse.js" type="text/javascript"></script>
</div>
</div>
</div>
</div>
</div>
<header class="navbar desktop-only" id="nav">
<div class="navbar-inner">
<div class="container-fluid">
<div class="pivotal-logo--container">
<a class="pivotal-logo" href="http://gopivotal.com"><span></span></a>
</div>
<ul class="nav pull-right">
<li class="navbar-link">
<a href="http://www.gopivotal.com/paas" id="paas-nav-link">PaaS</a>
</li>
<li class="navbar-link">
<a href="http://www.gopivotal.com/big-data" id="big-data-nav-link">BIG DATA</a>
</li>
<li class="navbar-link">
<a href="http://www.gopivotal.com/agile" id="agile-nav-link">AGILE</a>
</li>
<li class="navbar-link">
<a href="http://www.gopivotal.com/oss" id="oss-nav-link">OSS</a>
</li>
<li class="nav-search">
<a class="js-search-input-open" id="click-to-search"><span></span></a>
</li>
</ul>
</div>
<a href="http://www.gopivotal.com/contact">
<img id="get-started" src="http://www.gopivotal.com/sites/all/themes/gopo13/images/get-started.png">
</a>
</div>
</header>
<div class="main-wrap">
<div class="container-fluid">
<!-- Google CSE Search Box -->
<div id='docs-search'>
<gcse:search></gcse:search>
</div>
<div id='all-docs-link'>
<a href="http://docs.gopivotal.com/">All Documentation</a>
</div>
<div class="container">
<div id="sub-nav" class="nav-container">
<!-- Collapsible left-navigation-->
<ul class="accordion" id="accordion-1">
<!-- REPLACE <li/> NODES-->
<li>
<a href="index.html">Home</a></br>
<li>
<a href="PivotalHD.html">Pivotal HD 2.0.1</a>
<ul>
<li>
<a href="PHDEnterprise2.0.1ReleaseNotes.html">PHD Enterprise 2.0.1 Release Notes</a>
</li>
</ul>
<ul>
<li>
<a href="PHDInstallationandAdministration.html">PHD Installation and Administration</a>
<ul>
<li>
<a href="OverviewofPHD.html">Overview of PHD</a>
</li>
</ul>
<ul>
<li>
<a href="InstallationOverview.html">Installation Overview</a>
</li>
</ul>
<ul>
<li>
<a href="PHDInstallationChecklist.html">PHD Installation Checklist</a>
</li>
</ul>
<ul>
<li>
<a href="InstallingPHDUsingtheCLI.html">Installing PHD Using the CLI</a>
</li>
</ul>
<ul>
<li>
<a href="UpgradeChecklist.html">Upgrade Checklist</a>
</li>
</ul>
<ul>
<li>
<a href="UpgradingPHDUsingtheCLI.html">Upgrading PHD Using the CLI</a>
</li>
</ul>
<ul>
<li>
<a href="AdministeringPHDUsingtheCLI.html">Administering PHD Using the CLI</a>
</li>
</ul>
<ul>
<li>
<a href="PHDFAQFrequentlyAskedQuestions.html">PHD FAQ (Frequently Asked Questions)</a>
</li>
</ul>
<ul>
<li>
<a href="PHDTroubleshooting.html">PHD Troubleshooting</a>
</li>
</ul>
</li>
</ul>
<ul>
<li>
<a href="StackandToolsReference.html">Stack and Tools Reference</a>
<ul>
<li>
<a href="OverviewofApacheStackandPivotalComponents.html">Overview of Apache Stack and Pivotal Components</a>
</li>
</ul>
<ul>
<li>
<a href="ManuallyInstallingPivotalHD2.0Stack.html">Manually Installing Pivotal HD 2.0 Stack</a>
</li>
</ul>
<ul>
<li>
<a href="ManuallyUpgradingPivotalHDStackfrom1.1.1to2.0.html">Manually Upgrading Pivotal HD Stack from 1.1.1 to 2.0</a>
</li>
</ul>
<ul>
<li>
<a href="PivotalHadoopEnhancements.html">Pivotal Hadoop Enhancements</a>
</li>
</ul>
<ul>
<li>
<a href="Security.html">Security</a>
</li>
</ul>
</li>
</ul>
</li>
<li>
<a href="PivotalCommandCenter.html">Pivotal Command Center 2.2.1</a>
<ul>
<li>
<a href="PCC2.2.1ReleaseNotes.html">PCC 2.2.1 Release Notes</a>
</li>
</ul>
<ul>
<li>
<a href="PCCUserGuide.html">PCC User Guide</a>
<ul>
<li>
<a href="PCCOverview.html">PCC Overview</a>
</li>
</ul>
<ul>
<li>
<a href="PCCInstallationChecklist.html">PCC Installation Checklist</a>
</li>
</ul>
<ul>
<li>
<a href="InstallingPCC.html">Installing PCC</a>
</li>
</ul>
<ul>
<li>
<a href="UsingPCC.html">Using PCC</a>
</li>
</ul>
<ul>
<li>
<a href="CreatingaYUMEPELRepository.html">Creating a YUM EPEL Repository</a>
</li>
</ul>
<ul>
<li>
<a href="CommandLineReference.html">Command Line Reference</a>
</li>
</ul>
</li>
</ul>
</li>
<li>
<a href="PivotalHAWQ.html">Pivotal HAWQ 1.2.0</a>
<ul>
<li>
<a href="HAWQ1.2.0.1ReleaseNotes.html">HAWQ 1.2.0.1 Release Notes</a>
</li>
</ul>
<ul>
<li>
<a href="HAWQInstallationandUpgrade.html">HAWQ Installation and Upgrade</a>
<ul>
<li>
<a href="PreparingtoInstallHAWQ.html">Preparing to Install HAWQ</a>
</li>
</ul>
<ul>
<li>
<a href="InstallingHAWQ.html">Installing HAWQ</a>
</li>
</ul>
<ul>
<li>
<a href="InstallingtheHAWQComponents.html">Installing the HAWQ Components</a>
</li>
</ul>
<ul>
<li>
<a href="UpgradingHAWQandComponents.html">Upgrading HAWQ and Components</a>
</li>
</ul>
<ul>
<li>
<a href="HAWQConfigurationParameterReference.html">HAWQ Configuration Parameter Reference</a>
</li>
</ul>
</li>
</ul>
<ul>
<li>
<a href="HAWQAdministration.html">HAWQ Administration</a>
<ul>
<li>
<a href="HAWQOverview.html">HAWQ Overview</a>
</li>
</ul>
<ul>
<li>
<a href="HAWQQueryProcessing.html">HAWQ Query Processing</a>
</li>
</ul>
<ul>
<li>
<a href="UsingHAWQtoQueryData.html">Using HAWQ to Query Data</a>
</li>
</ul>
<ul>
<li>
<a href="ConfiguringClientAuthentication.html">Configuring Client Authentication</a>
</li>
</ul>
<ul>
<li>
<a href="KerberosAuthentication.html">Kerberos Authentication</a>
</li>
</ul>
<ul>
<li>
<a href="ExpandingtheHAWQSystem.html">Expanding the HAWQ System</a>
</li>
</ul>
<ul>
<li>
<a href="HAWQInputFormatforMapReduce.html">HAWQ InputFormat for MapReduce</a>
</li>
</ul>
<ul>
<li>
<a href="HAWQFilespacesandHighAvailabilityEnabledHDFS.html">HAWQ Filespaces and High Availability Enabled HDFS</a>
</li>
</ul>
<ul>
<li>
<a href="SQLCommandReference.html">SQL Command Reference</a>
</li>
</ul>
<ul>
<li>
<a href="ManagementUtilityReference.html">Management Utility Reference</a>
</li>
</ul>
<ul>
<li>
<a href="ClientUtilityReference.html">Client Utility Reference</a>
</li>
</ul>
<ul>
<li>
<a href="HAWQServerConfigurationParameters.html">HAWQ Server Configuration Parameters</a>
</li>
</ul>
<ul>
<li>
<a href="HAWQEnvironmentVariables.html">HAWQ Environment Variables</a>
</li>
</ul>
<ul>
<li>
<a href="HAWQDataTypes.html">HAWQ Data Types</a>
</li>
</ul>
<ul>
<li>
<a href="SystemCatalogReference.html">System Catalog Reference</a>
</li>
</ul>
<ul>
<li>
<a href="hawq_toolkitReference.html">hawq_toolkit Reference</a>
</li>
</ul>
</li>
</ul>
<ul>
<li>
<a href="PivotalExtensionFrameworkPXF.html">Pivotal Extension Framework (PXF)</a>
<ul>
<li>
<a href="PXFInstallationandAdministration.html">PXF Installation and Administration</a>
</li>
</ul>
<ul>
<li>
<a href="PXFExternalTableandAPIReference.html">PXF External Table and API Reference</a>
</li>
</ul>
</div><!--end of sub-nav-->
<h3 class="title-container">Client Utility Reference</h3>
<div class="content">
<!-- Python script replaces main content -->
<div id ="main"><div style="visibility:hidden; height:2px;">Pivotal Product Documentation : Client Utility Reference</div><div class="wiki-content group" id="main-content">
<p>This section provides references for the command-line client utilities provided with HAWQ. HAWQ uses standard PostgreSQL client programs, but also provides additional management utilities to administer a distributed HAWQ DBMS.</p><p>The HAWQ client programs are located in $GPHOME/bin.</p><p><style type="text/css">/*<![CDATA[*/
div.rbtoc1400035794976 {padding: 0px;}
div.rbtoc1400035794976 ul {list-style: disc;margin-left: 0px;}
div.rbtoc1400035794976 li {margin-left: 0px;padding-left: 0px;}
/*]]>*/</style><div class="toc-macro rbtoc1400035794976">
<ul class="toc-indentation">
<li><a href="#ClientUtilityReference-createdb">createdb</a></li>
<li><a href="#ClientUtilityReference-createlang">createlang</a></li>
<li><a href="#ClientUtilityReference-createuser">createuser</a></li>
<li><a href="#ClientUtilityReference-dropdb">dropdb</a></li>
<li><a href="#ClientUtilityReference-dropuser">dropuser</a></li>
<li><a href="#ClientUtilityReference-pg_dump">pg_dump</a></li>
<li><a href="#ClientUtilityReference-pg_dumpall">pg_dumpall</a></li>
<li><a href="#ClientUtilityReference-pg_restore">pg_restore</a></li>
<li><a href="#ClientUtilityReference-psql">psql</a></li>
<li><a href="#ClientUtilityReference-vacuumdb">vacuumdb</a></li>
</ul>
</div></p><h2 id="ClientUtilityReference-createdb">createdb</h2><p>Creates a new database.</p><h3 id="ClientUtilityReference-Synopsis">Synopsis</h3><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="theme: Confluence; brush: sql; gutter: false" style="font-size:12px;">createdb [connection_option ...] [-D tablespace] [-E encoding]
[-O owner] [-T template] [-e] [dbname ['description']] createdb --help | --version</pre>
</div></div><h3 id="ClientUtilityReference-Description">Description</h3><p>Creates a new database in a HAWQ system. It is a wrapper around the SQL command CREATE DATABASE.</p><p align="LEFT">When you create a database with this command, you will own the new database. You can specify a different owner using the -O option, if you have the appropriate privileges.</p><h3 id="ClientUtilityReference-Options">Options</h3><pre>dbname</pre><p style="margin-left: 30.0px;">Select a unique name for the new database in the HAWQ system. If you do not specify a name, the utility reads the environment variables PGDATABASE, PGUSER , or defaults to the current system user.</p><pre>description </pre><p align="LEFT" style="margin-left: 30.0px;">Describe the newly created database. Enclose white space within quotes.</p><pre>-D tablespace <span> </span>| --tablespace tablespace</pre><p style="margin-left: 30.0px;">The default tablespace for the database.</p><pre>-e echo</pre><p style="margin-left: 30.0px;">Echo the commands that createdb generates and send to the server.</p><pre>-E encoding <span> </span>| --encoding encoding</pre><p style="margin-left: 30.0px;">Character set encoding used in the new database. Specify a string constant (such as 'UTF8'), an integer encoding number, or DEFAULT to use the default encoding.</p><pre>-O <em>owner </em><span style="font-size: medium;"> </span>| --owner owner</pre><p style="margin-left: 30.0px;">The name of the database owner. Defaults to the user executing the command.</p><pre>-T <em>template </em><span style="font-size: medium;"> </span>| --template template</pre><p style="margin-left: 30.0px;">The name of the template used to create the new database. Defaults to <em>template1</em><span style="font-size: medium;"> </span>.</p><h3 id="ClientUtilityReference-ConnectionOptions">Connection Options</h3><pre>-h host <span> </span>| --host host</pre><p style="margin-left: 30.0px;">The host name of the HAWQ master database server. If not specified, reads the name from the environment variable PGHOST or defaults to localhost.</p><pre>-p <em>port </em><span style="font-size: medium;"> </span>| --port port</pre><p style="margin-left: 30.0px;">The TCP port where the HAWQ master database server listens for connections. If not specified, reads the environment variable PGPORT, or defaults to 5432.</p><pre>-U <em>username </em><span style="font-size: medium;"> </span>| --username username</pre><p style="margin-left: 30.0px;">Specifies the database role name used to connect. If not specified, reads the environment variable PGUSER or defaults to the current system role name.</p><pre>-w | --no-password</pre><p style="margin-left: 30.0px;">Use this to run automated batch jobs and scripts. In general, if the server requires password authentication, ensure that it can be accessed through a .pgpass file. Otherwise, the connection attempt will fail.</p><pre>-W | --password</pre><p style="margin-left: 30.0px;">Force a password prompt.</p><h3 id="ClientUtilityReference-Examples">Examples</h3><p align="LEFT">To create the database <em>test </em><span style="font-size: medium;"> </span>using the default options:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="theme: Confluence; brush: sql; gutter: false" style="font-size:12px;">createdb test</pre>
</div></div><p>To create the database, <em>demo, </em><span style="font-size: medium;"> </span>on <em>gpmaster </em><span style="font-size: medium;"> </span>using port <em>54321</em><span style="font-size: medium;"> </span>, with the <em>LATIN1 </em>encoding scheme:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="theme: Confluence; brush: sql; gutter: false" style="font-size:12px;">createdb -p 54321 -h gpmaster -E LATIN1 demo</pre>
</div></div><h3 id="ClientUtilityReference-SeeAlso">See Also</h3><p>CREATE DATABASE</p><h2 id="ClientUtilityReference-createlang">createlang</h2><p>Defines a new procedural language for a database.</p><h3 id="ClientUtilityReference-Synopsis.1">Synopsis</h3><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="theme: Confluence; brush: sql; gutter: false" style="font-size:12px;">createlang[connection_option ...] [-e] langname [[-d]dbname]
createlang [connection-option ...] -l dbname
createlang --help | --version </pre>
</div></div><h3 id="ClientUtilityReference-Description.1">Description</h3><p>createlang is a utility for adding a new programming language to a database. createlang is a wrapper around the CREATE LANGUAGE SQL command.</p><p>The procedural language packages currently included in the standard HAWQ Database distribution are: PL/pgSQL, and PL/Python. The PL/pgSQL language is already registered in all databases by default.</p><p>A language handler has also been added for PL/R, but the PL/R language package is not pre-installed with the HAWQ Database. See the section on Procedural Languages in the PostgreSQL documentation for more information.</p><h3 id="ClientUtilityReference-Options.1">Options</h3><pre>langname</pre><p style="margin-left: 30.0px;">Specifies the name of the procedural programming language to be defined.</p><pre>[-d] <em>dbname </em><span style="font-size: medium;"> </span><span> </span>| [--dbname] <em>dbname </em></pre><p style="margin-left: 30.0px;">Specifies to which database the language should be added. The default is to use the PGDATABASE environment variable setting, or the same name as the current system user.</p><pre>-e | --echo</pre><p style="margin-left: 30.0px;">Echo the commands that createlang generates and send to the server.</p><pre>-l dbname <span> </span>| --list dbname </pre><p style="margin-left: 30.0px;">Show a list of already-installed languages in the target database.</p><h3 id="ClientUtilityReference-ConnectionOptions.1">Connection Options</h3><p>-h <em>host </em><span style="font-size: medium;"> </span>| --host <em>host </em></p><p style="margin-left: 30.0px;">The host name of the machine on which the HAWQ master database server is running. If not specified, reads from the environment variable PGHOST or defaults to localhost.</p><p>-p <em>port </em><span style="font-size: medium;"> </span>| --port <em>port </em></p><p style="margin-left: 30.0px;">The TCP port on which the HAWQ master database server is listening for connections. If not specified, reads from the environment variable PGPORT or defaults to 5432.</p><pre>-U username <span> </span>| --username username</pre><p style="margin-left: 30.0px;">The database role name to connect as. If not specified, reads from the environment variable PGUSER or defaults to the current system role name.</p><pre><span><span> </span>-w | --no-password -W | --password </span></pre><p align="LEFT" style="margin-left: 30.0px;">Never issue a password prompt. If the server requires password authentication and a password is not available by other means (such as a .pgpass 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.</p><pre>-W | --password</pre><p style="margin-left: 30.0px;">Force a password prompt.<span style="font-size: medium;"><span style="font-size: medium;"> </span></span></p><h3 id="ClientUtilityReference-SeeAlso.1">See Also</h3><p>CREATE LANGUAGE, droplang<span style="font-size: medium;"><span style="font-size: medium;"><span style="font-size: medium;"><span style="font-size: small;"> </span> </span></span></span></p><h2 id="ClientUtilityReference-createuser">createuser</h2><p>Creates a new database role.</p><h3 id="ClientUtilityReference-Synopsis.2">Synopsis</h3><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="theme: Confluence; brush: sql; gutter: false" style="font-size:12px;">createuser [connection_option ...] [role_attribute ...] [-e] role_name
createuser --help | --version</pre>
</div></div><h3 id="ClientUtilityReference-Description.2">Description</h3><p>createuser creates a new HAWQ role. You must be a superuser or user with CREATEROLE privileges. To create a new superuser, you must be a superuser.</p><p align="LEFT"><strong>Note</strong>: Making someone a superuser grants privileges such as bypassing access permission checks within the database.</p><p>createuser is a wrapper around the SQL command CREATE ROLE.</p><h3 id="ClientUtilityReference-Options.2">Options</h3><pre>role_name</pre><p style="margin-left: 30.0px;">Select a unique name for the role to be created. This name must be different from all existing roles in this HAWQ installation.</p><pre>-c number <span> </span>| --connection-limit number</pre><p style="margin-left: 30.0px;">Set a maximum number of connections for the new role. The default is no limit.</p><pre>-D | --no-createdb</pre><p style="margin-left: 30.0px;"><span style="font-size: medium;"><span style="font-size: medium;"><span style="font-size: medium;"> </span></span></span>By default, the new role cannot create databases.</p><pre>-d | --createdb</pre><p style="margin-left: 30.0px;"><span style="font-size: medium;"><span style="font-size: medium;"><span style="font-size: medium;"> </span></span></span>The new role can create databases.</p><pre>-e | --echo</pre><p style="margin-left: 30.0px;"><span style="font-size: medium;"><span style="font-size: medium;"><span style="font-size: medium;"> </span></span></span>Echo the commands that createuser generates and sends to the server.</p><pre>-E | --encrypted</pre><p style="margin-left: 30.0px;">Encrypts and stores the password for the role. If not specified, uses the default password.</p><pre>-i | --inherit</pre><p style="margin-left: 30.0px;">By default, the new role inherits the privileges of the groups to which it belongs.</p><pre>-I | --no-inherit</pre><p style="margin-left: 30.0px;">The new role will not inherit the privileges of the groups to which it belongs.</p><pre>-l | --login</pre><p><span style="font-size: medium;"><span style="font-size: medium;"><span style="font-size: medium;"> </span></span></span></p><p align="LEFT" style="margin-left: 30.0px;">By default, the new role can log in to HAWQ.<span style="font-size: medium;"><span style="font-size: medium;"> </span></span></p><pre>-L | --no-login</pre><p><span style="font-size: medium;"><span style="font-size: medium;"><span style="font-size: medium;"> </span></span></span></p><p align="LEFT" style="margin-left: 30.0px;">The new role cannot log in to HAWQ (a group-level role).</p><pre>-N | --unencrypted</pre><p style="margin-left: 30.0px;">Does not encrypt the stored password for the role. If not specified, the default password behavior is used.</p><pre>-P | --pwprompt</pre><p style="margin-left: 30.0px;">If given, createuser prompts you for the password for the new role. Use this only if you want to enforce password authentication.</p><pre>-r | --createrole</pre><p style="margin-left: 30.0px;">The new role can create new roles (CREATEROLE privilege).</p><p><span style="font-size: medium;"><span style="font-size: medium;"> </span></span></p><pre>-R | --no-createrole</pre><p style="margin-left: 30.0px;">The new role cannot create new roles. This is the default.</p><pre>-s | --superuser</pre><p style="margin-left: 30.0px;">Create the new role as superuser.</p><pre>-S | --no-superuser</pre><p style="margin-left: 30.0px;">Do not create the new role to be a superuser. This is the default.</p><h3 id="ClientUtilityReference-ConnectionOptions.2">Connection Options</h3><pre>-h host <span> </span>| --host host</pre><p style="margin-left: 30.0px;">The host name of the HAWQ master database server. If not specified, reads the name from the environment variable PGHOST or defaults to localhost.</p><pre>-p port <span> </span>| --port port</pre><p style="margin-left: 30.0px;">The TCP port where the HAWQ master database server listens for connections. If not specified, reads the environment variable PGPORT, or defaults to 5432.</p><pre>- U username <span style="font-size: medium;"> </span>| --username <em>username</em></pre><p style="margin-left: 30.0px;">Specifies the database role name used to connect. If not specified, reads the environment variable PGUSER or defaults to the current system role name.</p><pre>-w | --no-password</pre><p style="margin-left: 30.0px;">Use this to run automated batch jobs and scripts. In general, if the server requires password authentication, ensure that it can be accessed through a .pgpass file. Otherwise the connection attempt will fail.</p><pre>-W | --password</pre><p style="margin-left: 30.0px;">Force a password prompt.</p><h3 id="ClientUtilityReference-Examples.1">Examples</h3><p align="LEFT">To create the role, joe, with default options:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="theme: Confluence; brush: sql; gutter: false" style="font-size:12px;">createuser joe
Shall the new role be a superuser? (y/n) n
Shall the new role be allowed to create databases? (y/n) n
Shall the new role be allowed to create more new roles? (y/n) n
CREATE ROLE</pre>
</div></div><p>To create the role, <em>joe, </em><span style="font-size: medium;"> </span>with default connection options:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="theme: Confluence; brush: sql; gutter: false" style="font-size:12px;">createuser -h masterhost -p 54321 -S -D -R -e joe
CREATE ROLE joe NOSUPERUSER NOCREATEDB NOCREATEROLE INHERIT
LOGIN;
CREATE ROLE</pre>
</div></div><p>To create the role, <em>joe </em><span style="font-size: medium;"> </span>as a superuser, and provide password prompts:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="theme: Confluence; brush: sql; gutter: false" style="font-size:12px;">createuser -P -s -e joe
Enter password for new role: admin123
Enter it again: admin123
CREATE ROLE joe PASSWORD 'admin123' SUPERUSER CREATEDB
CREATEROLE INHERIT LOGIN;
CREATE ROLE</pre>
</div></div><p>Note: The example shows how the new password is echoed if the -e option is used.</p><h3 id="ClientUtilityReference-SeeAlso.2">See Also</h3><p>CREATE ROLE</p><h2 id="ClientUtilityReference-dropdb">dropdb</h2><p>Removes an existing database.</p><h3 id="ClientUtilityReference-Synopsis.3">Synopsis</h3><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="theme: Confluence; brush: sql; gutter: false" style="font-size:12px;">dropdb [connection_option ...] [-e] [-i] dbname
dropdb --help | --version</pre>
</div></div><h3 id="ClientUtilityReference-Description.3">Description</h3><p>dropdb removes an existing database. The user who executes this command must be a superuser or own the database being dropped.</p><p>dropdb is a wrapper around the SQL command DROP DATABASE</p><h3 id="ClientUtilityReference-Options.3">Options</h3><pre>dbname</pre><p style="margin-left: 30.0px;">The unique name of the database being removed.</p><pre>-e | --echo</pre><p style="margin-left: 30.0px;">Echoes and sends commands dropdb generates to the server.</p><pre>-i | --interactive</pre><p style="margin-left: 30.0px;">Presents verification prompts to ensure that you want to perform this process.</p><h3 id="ClientUtilityReference-ConnectionOptions.3">Connection Options</h3><pre>-h host <span> </span>| --host host</pre><p style="margin-left: 30.0px;">The host name of the HAWQ master database server. If not specified, reads the name from the environment variable PGHOST or defaults to localhost.</p><pre>-p port <span> </span>| --port port</pre><p align="LEFT" style="margin-left: 30.0px;">The TCP port where the HAWQ master database server listens for connections. If not specified, reads the environment variable PGPORT, or defaults to 5432.</p><pre>-U username <span style="font-size: medium;"> </span>| --username <em>username</em></pre><p style="margin-left: 30.0px;">Specifies the database role name used to connect. If not specified, reads the environment variable PGUSER or defaults to the current system role name.</p><pre>-w | --no-password</pre><p style="margin-left: 30.0px;">Use this to run automated batch jobs and scripts. In general, if the server requires password authentication, ensure that it can be accessed through a .pgpass file. Otherwise the connection attempt will fail.</p><pre>-W | --password</pre><p style="margin-left: 30.0px;">Force a password prompt.</p><h3 id="ClientUtilityReference-Examples.2">Examples</h3><p>To destroy the database, <em>demo </em><span style="font-size: medium;"> </span>using default connection parameters:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="theme: Confluence; brush: sql; gutter: false" style="font-size:12px;"> dropdb demo</pre>
</div></div><p>To destroy the database, <em>demo </em><span style="font-size: medium;"> </span>using verification prompts:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="theme: Confluence; brush: sql; gutter: false" style="font-size:12px;">dropdb -p 54321 -h masterhost -i -e demo
Database "demo" will be permanently deleted.
Are you sure? (y/n) y
DROP DATABASE "demo"
DROP DATABASE</pre>
</div></div><h3 id="ClientUtilityReference-SeeAlso.3">See Also</h3><p>DROP DATABASE</p><h2 id="ClientUtilityReference-dropuser">dropuser</h2><p>Removes a database role.</p><h3 id="ClientUtilityReference-Synopsis.4">Synopsis</h3><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="theme: Confluence; brush: sql; gutter: false" style="font-size:12px;">dropuser [connection_option ...] [-e] [-i] role_name
dropuser --help | --version</pre>
</div></div><h3 id="ClientUtilityReference-Description.4">Description</h3><p>dropuser removes an existing role from HAWQ. Only superusers and users with CREATEROLE privilege can remove roles. To remove a superuser role, you must be a superuser.</p><p>dropuser is a wrapper around the SQL command DROP ROLE.</p><h3 id="ClientUtilityReference-Options.4">Options</h3><pre>role_name</pre><p style="margin-left: 30.0px;">Specifies the name of the role to be removed. If you do not specify the name, you will be prompted on the command line.</p><pre>-e | --echo</pre><p style="margin-left: 30.0px;">Echo and send the commands that dropuser generates to the server.</p><pre>-i | --interactive</pre><p style="margin-left: 30.0px;">Prompt for confirmation before removing the role.</p><h3 id="ClientUtilityReference-ConnectionOptions.4">Connection Options</h3><pre>-h host <span> </span>| --host host</pre><p style="margin-left: 30.0px;">The host name of the HAWQ master database server. If not specified, reads the name from the environment variable PGHOST or defaults to localhost</p><pre>-p port <span style="font-size: medium;"> </span>| --port <em>port</em></pre><p style="margin-left: 30.0px;">The TCP port where the HAWQ master database server listens for connections. If not specified, reads the environment variable PGPORT, or defaults to 5432.</p><pre>-U username <span style="font-size: medium;"> </span>| --username username</pre><p style="margin-left: 30.0px;">The database role name to connect as. If not specified, reads from the environment variable PGUSER or defaults to the current system role name.</p><pre>-w | --no-password</pre><p style="margin-left: 30.0px;">Use this to run automated batch jobs and scripts. In general, if the server requires password authentication ensure that it can be accessed through a .pgpass file. Otherwise the connection attempt will fail.</p><pre>-W | --password</pre><p style="margin-left: 30.0px;">Force a password prompt.</p><h3 id="ClientUtilityReference-Examples.3">Examples</h3><p>To remove the role, <em>joe </em><span style="font-size: medium;"> </span>using default connection options:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="theme: Confluence; brush: sql; gutter: false" style="font-size:12px;">dropuser joe
DROP ROLE</pre>
</div></div><p>To remove the role, <em>joe </em><span style="font-size: medium;"> </span>using verification prompts:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="theme: Confluence; brush: sql; gutter: false" style="font-size:12px;">dropuser -p 54321 -h masterhost -i -e joe
Role "joe" will be permanently removed.
Are you sure? (y/n) y
DROP ROLE "joe"
DROP ROLE</pre>
</div></div><h3 id="ClientUtilityReference-SeeAlso.4">See Also</h3><p>DROP ROLE</p><h2 id="ClientUtilityReference-pg_dump">pg_dump</h2><p>Extracts a database into a single script file or other archive file.</p><h3 id="ClientUtilityReference-Synopsis.5">Synopsis</h3><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="theme: Confluence; brush: sql; gutter: false" style="font-size:12px;">pg_dump[connection_option ...] [dump_option ...] dbname</pre>
</div></div><h3 id="ClientUtilityReference-Description.5">Description</h3><p>pg_dump is a standard PostgreSQL utility for backing up a database, and is also supported in HAWQ. It creates a single (non-parallel) dump file.</p><p>Use pg_dump if you are migrating your data to a different database vendor, or to a HAWQ system with a different segment configuration. For example, a different HAWQ system configuration may have more or fewer segment instances.</p><p>To restore dump files:</p><ul><li>From archive format you must use the pg_restore utility.</li><li>From plain text format you can use a client program such as psql.</li></ul><p>About using pg_dump utility with HAWQ:</p><ul><li>The dump operation can take a several hours for very large databases. Make sure you have sufficient disk space to create the dump file.</li><li>To migrate data from one HAWQ system to another, use the --gp-syntax command-line option to include the DISTRIBUTED BY clause in CREATE TABLE statements. This ensures that HAWQ table data is distributed with the correct distribution key columns upon restore.</li><li>pg_dump makes consistent backups even if the database is being used concurrently.</li><li>pg_dump does not block other users accessing the database (readers or writers).</li></ul><p align="LEFT">When used with one of the archive file formats and combined with pg_restore, pg_dump provides a flexible archival and transfer mechanism. Once pg_dump backs up the entire database, you can use pg_restore to examine the archive and select the parts of the database you want to restore.</p><p align="LEFT">The <em>custom </em><span style="font-size: medium;"> </span>format (-Fc) is flexible. You can select and reorder all the archived items, and compresses the archive by default.</p><p align="LEFT">The tar format (-Ft) is not compressed and does not reorder data when loading. It can be manipulated with standard UNIX tools such as tar.</p><h3 id="ClientUtilityReference-Options.5">Options</h3><pre>dbname</pre><p style="margin-left: 30.0px;">Specifies the name of the database to be dumped. If the database is not specified, the environment variable PGDATABASE is used. If PGDATABASE is not set, the user name specified for the connection is used.</p><h4 id="ClientUtilityReference-DumpOptions">Dump Options</h4><pre>-a | --data-only</pre><p style="margin-left: 30.0px;">Dumps the data, not the schema (data definitions). This option is only meaningful for plain-text format. For archive formats, specify the option when you call pg_restore</p><pre>-b | --blobs</pre><p style="margin-left: 30.0px;">Include large objects in the dump. This is the default behavior except when --schema, --table, or --schema-only is specified.</p><pre>-c | --clean</pre><p style="margin-left: 30.0px;">Adds commands to the text output file to drop database objects before creating them. Objects are not dropped before the dump operation begins. The DROP commands are added to the DDL dump output files so that when you restore, the DROP commands run before the CREATE commands. This option is only works with plain-text format. For archive formats, you may specify the option when you call pg_restore</p><pre>-C | --create</pre><p style="margin-left: 30.0px;">Begin the output with a command to create the database itself and reconnect to the created database. With a script of this form, it doesn’t matter which database you connect to before running the script. This option is only meaningful for the plain-text format. For the archive formats, you may specify the option when you call pg_restore</p><pre>-d | --inserts</pre><p style="margin-left: 30.0px;">Dump data as INSERT commands (rather than COPY). This will make restoration very slow; it is mainly useful for making dumps that can be loaded into non-PostgreSQL-based databases. Also, since this option generates a separate command for each row, an error in reloading a row causes only that row to be lost rather than the entire table contents. Note that the restore may fail altogether if you have rearranged column order. The -D option is safe against column order changes, though even slower.</p><pre>-D | --column-inserts | --attribute-inserts</pre><p style="margin-left: 30.0px;">Dump data as INSERT commands with explicit column names (INSERT INTO table (<em>column</em><span style="font-size: small;"> </span>, ...) VALUES ...). This will make restoration very slow; it is useful for making dumps that can be loaded into non-PostgreSQL-based databases. Also, since this option generates a separate command for each row, an error in reloading a row causes only that row to be lost rather than the entire table contents.</p><pre>-E <em>encoding </em><span style="font-size: medium;"> </span>| --encoding=encoding</pre><p style="margin-left: 30.0px;">Create the dump in the specified character set encoding. By default, the dump is created in the database encoding, or you can set the PGCLIENTENCODING environment variable to the desired dump encoding.</p><pre> -f file | --file=file</pre><p align="LEFT" style="margin-left: 30.0px;">Send output to the specified file. If this is omitted, the standard output is used.</p><pre>-F p|c|t | --format=plain|custom|tar</pre><p align="LEFT" style="margin-left: 60.0px;">Selects the format of the output:</p><pre> p | plain</pre><p style="margin-left: 60.0px;">— Output a plain-text SQL script file. This is the default.</p><pre> c | custom</pre><p style="margin-left: 60.0px;">— Output a custom archive suitable for input into pg_restore.This is the most flexible format in that it allows reordering of loading data as well as object definitions. This format is also compressed by default.</p><pre> t | tar</pre><p style="margin-left: 60.0px;">— Output a tar archive suitable for input into pg_restore. Using this archive format allows reordering and/or exclusion of database objects at the time the database is restored. It is also possible to limit which data is reloaded at restore time.</p><pre>-i | --ignore-version</pre><p style="margin-left: 30.0px;">Ignore version mismatch between pg_dump and the database server. pg_dump can dump from servers running previous releases of HAWQ (or PostgreSQL), but very old versions may not be supported anymore. Use this option if you need to override the version check. <strong>(This does not make sense. Ask question)</strong></p><pre>-n schema <span style="font-size: medium;"> </span>| --schema=<em>schema</em></pre><p style="margin-left: 30.0px;">Dump only schemas matching the schema pattern. This selects both the schema itself, and all its contained objects. If this option is not specified, all non-system schemas in the target database will be dumped. Multiple schemas can be selected by writing multiple -n switches. Since the schema parameter is interpreted as a pattern similar to psql’s \d commands, you can select multiple schemas using wildcard characters in the pattern. Add wildcards within quotes to prevent the shell from expanding the wildcards.</p><p align="LEFT" style="margin-left: 30.0px;"><strong>Note</strong>: When -n is specified, pg_dump does not dump database objects that the selected schema(s) may depend upon. Therefore, there is no guarantee that the results of a specific-schema dump can be successfully restored into a clean database.</p><p style="margin-left: 30.0px;"><strong>Note</strong>: Non-schema objects such as blobs are not dumped when -n is specified. You can add blobs back to the dump with the --blobs switch.<span style="font-size: medium;"><span style="font-size: medium;"><span style="font-size: medium;"><span style="font-size: medium;"><span style="font-size: medium;"> </span></span></span></span></span></p><pre>-N schema | --exclude-schema=schema</pre><p style="margin-left: 30.0px;">Do not dump any schemas matching the schema pattern. The schema pattern is interpreted according to the rules or -n. You can use -N more than once to exclude schemas matching several patterns. When both -n and -N are given, the utility dumps the schemas that match at least one -n switch but not the -N switches. If -N appears without -n, then schemas matching -N are excluded.</p><pre>-o | --oids</pre><p style="margin-left: 30.0px;">Dump object identifiers (OIDs) as part of the data for every table. Use of this option is not recommended for files that are intended to be restored into HAWQ.</p><pre>-O | --no-owner</pre><p style="margin-left: 30.0px;">Do not output commands to set ownership of objects to match the original database.</p><p align="LEFT" style="margin-left: 30.0px;">By default, pg_dump issues ALTER OWNER or SET SESSION AUTHORIZATION statements to set ownership of created database objects. To successfully run this script, you must be a superuser or own the objects in the script. Specify -O to make a script that can be restored by any user, and grant them ownership of all the objects. This option is only meaningful for the plain-text format. For the archive formats, you may specify the option when you call pg_restore.</p><pre>-s | --schema-only</pre><p style="margin-left: 30.0px;">Dump only the object definitions (schema), not data.</p><pre>-S username | --superuser=username</pre><p style="margin-left: 30.0px;">Specify the superuser name for disabling triggers. This is only relevant if --disable-triggers is used. It is better to leave this out, and instead start the resulting script as a superuser.</p><pre>-t table | --table=table</pre><p align="LEFT" style="margin-left: 30.0px;">Dump only tables (or views or sequences) matching the table pattern. Specify the table in the format schema.table.</p><p align="LEFT" style="margin-left: 30.0px;">To select multiple tables, write multiple -t switches. The table pattern is interpreted according to the rules used by psql’s \d commands; you can select multiple tables using wildcard characters in the pattern. Add wildcards within quotes to prevent the shell from expanding the wildcards. The -n and -N switches have no effect when you use -t. Tables selected by -t will be dumped regardless of the -n and -N switches, and non-table objects will not be dumped.</p><p align="LEFT" style="margin-left: 30.0px;"><strong>Note</strong>: When -t is specified, pg_dump does not dump any other database objects that the selected table(s) may depend upon. Therefore, there is no guarantee that the results of a specific-table dump can be successfully restored into a clean database.</p><p align="LEFT" style="margin-left: 30.0px;"><strong>Note</strong>: You cannot used -t to specify a child table partition. To dump a partitioned table, you must specify the parent table name.</p><pre>-T table | --exclude-table=table</pre><p style="margin-left: 30.0px;">Do not dump any tables matching the table pattern. The pattern is interpreted according to the same rules as -t. You can use -T more than once to exclude tables matching several patterns. When both -t and -T are given, the behavior is to dump just the tables that match at least one -t switch but no -T switches. If -T appears without -t, then tables matching -T are excluded from what is otherwise a normal dump.</p><pre>-v | --verbose</pre><p style="margin-left: 30.0px;">Specifies verbose mode. This will cause pg_dump to output detailed object comments and start/stop times to the dump file, and output progress messages to standard error.</p><pre>-x | --no-privileges | --no-acl</pre><p style="margin-left: 30.0px;">Prevent dumping of access privileges (GRANT/REVOKE commands).</p><pre>--disable-dollar-quoting</pre><p style="margin-left: 30.0px;">This option disables the use of dollar quoting for function bodies, and forces them to be quoted using SQL standard string syntax.</p><pre>--disable-triggers</pre><p align="LEFT" style="margin-left: 30.0px;">This option is relevant when creating a data-only dump. It instructs pg_dump to include commands to temporarily disable triggers on the target tables while the data is reloaded. Use this if you have triggers on the tables that you do not want to invoke during data reload. The commands emitted for --disable-triggers must be done as superuser. Specify a superuser name with -S, and be careful when starting the script as a superuser. This option only works for the plain-text format. For the archive formats, you may specify the option when you call pg_restore. --use-set-session-authorization</p><p style="margin-left: 30.0px;">Output SQL-standard SET SESSION AUTHORIZATION commands instead of ALTER OWNER commands to determine object ownership. This makes the dump more standards compatible, but depending on the history of the objects in the dump, may not restore properly. A dump using SET SESSION AUTHORIZATION will require superuser privileges to restore correctly, whereas ALTER OWNER requires lesser privileges.</p><pre>--gp-syntax | --no-gp-syntax</pre><p style="margin-left: 30.0px;">Use --gp-syntax to dump HAWQ syntax in the CREATE TABLE statements. This preserves the distribution policy (DISTRIBUTED BY or DISTRIBUTED RANDOMLY clauses) to dump a HAWQ table and to restore into other HAWQ systems. The default is to include HAWQ syntax when connected to a HAWQ system, and to exclude it when connected to a regular PostgreSQL system.</p><pre>-Z 0..9 | --compress=0..9</pre><p style="margin-left: 30.0px;">Specify the compression level to use in archive formats that support compression. Currently only the <em>custom </em><span style="font-size: medium;"> </span>archive format supports compression.</p><h3 id="ClientUtilityReference-ConnectionOptions.5">Connection Options</h3><pre>-h <em>host </em><span style="font-size: medium;"> </span>| --host host</pre><p style="margin-left: 30.0px;">The host name of the HAWQ master database server. If not specified, reads the name from the environment variable PGHOST or defaults to localhost.</p><pre>-p <em>port </em><span style="font-size: medium;"> </span>| --port port</pre><p style="margin-left: 30.0px;">The TCP port where the HAWQ master database server listens for connections. If not specified, reads the environment variable PGPORT, or defaults to 5432.</p><pre>-U username | --username username</pre><p style="margin-left: 30.0px;">The database role name to connect as. If not specified, reads from the environment variable PGUSER or defaults to the current system role name.</p><pre>-W | --password</pre><p style="margin-left: 30.0px;">Force a password prompt.</p><h3 id="ClientUtilityReference-Notes">Notes</h3><p>When a data-only dump is chosen and the option --disable-triggers is used, pg_dump disables triggers on user tables before inserting the data and re-enables them after the data has been inserted. Stopping restore before it is complete could leave the system catalogs in the wrong state.</p><p>Members of tar archives are limited to less than 8 GB. This is an inherent limitation of the tar file format. Therefore this format cannot be used if the textual representation of any one table exceeds that size. The total size of a tar archive or any other output format is not limited, except possibly by the operating system.</p><p align="LEFT">The dump file produced by pg_dump does not contain the statistics used by the optimizer to make query planning decisions. Therefore, it is wise to run ANALYZE after restoring from a dump file, to ensure good performance.</p><h3 id="ClientUtilityReference-Examples.4">Examples</h3><p align="LEFT">To dump a database called <em>mydb </em><span style="font-size: medium;"> </span>into a SQL-script file:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="theme: Confluence; brush: sql; gutter: false" style="font-size:12px;">pg_dump mydb > db.sql</pre>
</div></div><p>To reload a SQL-script into a new database, <em>newdb</em><span style="font-size: medium;"> </span>:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="theme: Confluence; brush: sql; gutter: false" style="font-size:12px;">psql -d newdb -f db.sql</pre>
</div></div><p>To dump a HAWQ database in tar file format and include distribution policy information:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="theme: Confluence; brush: sql; gutter: false" style="font-size:12px;">pg_dump -Ft --gp-syntax mydb > db.tar</pre>
</div></div><p><span style="font-size: medium;"><span style="font-size: medium;"> </span></span>To dump a database into a custom-format archive file:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="theme: Confluence; brush: sql; gutter: false" style="font-size:12px;">pg_dump -Fc mydb > db.dump</pre>
</div></div><p>To reload an archive file into a new database named <em>newdb</em><span style="font-size: medium;"> </span>:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="theme: Confluence; brush: sql; gutter: false" style="font-size:12px;">pg_restore -d newdb db.dump</pre>
</div></div><p>To dump a single table named <em>mytab</em><span style="font-size: medium;"> </span>:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="theme: Confluence; brush: sql; gutter: false" style="font-size:12px;">pg_dump -t mytab mydb > db.sql</pre>
</div></div><p>To specify an upper-case or mixed-case name in -t and related switches, use double-quotes around the name. Otherwise it will be folded to lower case. Since double quotes are special to the shell, use the following syntax:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="theme: Confluence; brush: sql; gutter: false" style="font-size:12px;">pg_dump -t '"MixedCaseName"' mydb > mytab.sql</pre>
</div></div><h3 id="ClientUtilityReference-SeeAlso.5">See Also</h3><p>pg_dumpall, pg_restore, psql</p><h2 id="ClientUtilityReference-pg_dumpall">pg_dumpall</h2><p>Extracts all databases in a HAWQ system to a single script file or other archive file.</p><h3 id="ClientUtilityReference-Synopsis.6">Synopsis</h3><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="theme: Confluence; brush: sql; gutter: false" style="font-size:12px;">pg_dumpall [connection_option ...] [dump_option ...]</pre>
</div></div><h3 id="ClientUtilityReference-Description.6">Description</h3><p align="LEFT">pg_dumpall is a standard PostgreSQL utility for backing up all databases in PostgreSQL or HAWQ instances. It creates a single (non-parallel) dump file.</p><p>pg_dumpall creates a single script file that contains SQL commands. These commands are used as input to psql to restore the databases. pg_dumpall calls pg_dump for each database. It also dumps all the common global database objects.</p><p>This script also includes information about database users and groups, and access permissions that apply to databases as a whole.</p><p>You must connect as superuser to run pg_dumpall because the script reads tables from all databases to produce a complete dump. Also you need superuser privileges to add users and groups, and to create databases. The SQL script is written to the standard output. Shell operators can be used to redirect it into a file.</p><p>pg_dumpall needs to connect several times to the HAWQ master server once for each database. If you use password authentication you can store the password in a ~/.pgpass file.</p><h3 id="ClientUtilityReference-Options.6">Options</h3><h4 id="ClientUtilityReference-DumpOptions.1">Dump Options</h4><pre>-a | --data-only</pre><p style="margin-left: 30.0px;">Only dumps the data, not the schema (data definitions). This option only works for the plain-text format. For the archive formats, you can specify the option when you call pg_restore.</p><pre>-c | --clean</pre><p style="margin-left: 30.0px;">Output commands to drop database objects before creating them. This option only works for the plain-text format. For the archive formats, you can specify the option when you call pg_restore.</p><pre>-d | --inserts</pre><p style="margin-left: 30.0px;">Dump data as INSERT commands (rather than COPY). This restores the data slowly, but is useful for making dumps to load into non-PostgreSQL-based databases. Also, since this option generates a separate command for each row, an error in reloading a row is limited to a single row. Note that the restore may fail altogether if you have rearranged the column order. Using the -D option is safe from column order changes, though it is slower that -d.</p><pre>-D | --column-inserts | --attribute-inserts</pre><p style="margin-left: 30.0px;">Dumps data as INSERT commands with explicit column names (INSERT INTO table (<em>column</em><span style="font-size: small;"> </span>, ...) VALUES ...). This will make restoration very slow; it is used to load dumps into non-PostgreSQL-based databases. Also, since this option generates a separate command for each row, an error in reloading a row is limited to a single row.</p><pre>-F | --filespaces</pre><p align="LEFT" style="margin-left: 30.0px;">Dump filespace definitions.</p><pre>-g | --globals-only</pre><p align="LEFT" style="margin-left: 30.0px;">Dump only global objects (roles and tablespaces), no databases.</p><pre>-i | --ignore-version</pre><p style="margin-left: 30.0px;">Ignore version mismatch between pg_dump and the database server. pg_dump can dump from servers running previous releases of HAWQ (or PostgreSQL), but very old versions may not be supported. Use this option if you need to override the version check.</p><p align="LEFT">-o | --oids</p><p style="margin-left: 30.0px;">Dump object identifiers (OIDs) as part of the data for every table. Pivotal recommends you use this option to restore files into HAWQ.</p><p align="LEFT">-O | --no-owner</p><p style="margin-left: 30.0px;">Do not output commands to set ownership of objects to match the original database.</p><p align="LEFT" style="margin-left: 30.0px;">By default, pg_dump issues ALTER OWNER or SET SESSION AUTHORIZATION statements to set ownership of created database objects. To successfully run this script, you must be a superuser or own the objects in the script. Specify -O to make a script that can be restored by any user, and grant them ownership of all the objects. This option is only meaningful for the plain-text format. For the archive formats, you may specify the option when you call pg_restore.</p><pre>-r | --resource-queues</pre><p style="margin-left: 30.0px;">Dump resource queue definitions.</p><pre>-s | --schema-only</pre><p style="margin-left: 30.0px;">Dump only the object definitions (schema), not data.</p><pre>-S username | --superuser=username</pre><p style="margin-left: 30.0px;">Specify the superuser name for disabling triggers. This is only relevant if --disable-triggers is used. It is better to omit this option, and instead start the resulting script as a superuser.</p><pre>-v | --verbose</pre><p align="LEFT" style="margin-left: 30.0px;">Specifies verbose mode. This will cause pg_dump to output detailed object comments and start/stop times to the dump file, and send progress messages to standard error.</p><pre>-x | --no-privileges | --no-acl</pre><p style="margin-left: 30.0px;">Prevent dumping of access privileges (GRANT/REVOKE commands).</p><pre>--disable-dollar-quoting</pre><p align="LEFT" style="margin-left: 30.0px;">This option disables the use of dollar quoting for function bodies, and forces them to be quoted using SQL standard string syntax.</p><pre>--disable-triggers</pre><p align="LEFT" style="margin-left: 30.0px;">This option is only relevant when creating a data-only dump. It instructs pg_dumpall to include commands to temporarily disable triggers on the target tables while the data is reloaded. Use this if you have triggers on the tables that you do not want to invoke during data reload. The commands emitted for --disable-triggers must be done as superuser. Specify a superuser name with -S, and be careful when starting the script as a superuser.</p><pre>--use-set-session-authorization</pre><p style="margin-left: 30.0px;">Output SQL-standard SET SESSION AUTHORIZATION commands instead of ALTER OWNER commands to determine object ownership. This makes the dump more standards-compatible, but depending on the history of the objects in the dump, may not restore properly. A dump using SET SESSION AUTHORIZATION will require superuser privileges to restore correctly, whereas ALTER OWNER requires lesser privileges.</p><pre>--gp-syntax</pre><p style="margin-left: 30.0px;">Output HAWQ syntax in the CREATE TABLE statements. This preserves the distribution policy (DISTRIBUTED BY or DISTRIBUTED RANDOMLY clauses) to dump a HAWQ table and to restore into other HAWQ systems.</p><h3 id="ClientUtilityReference-ConnectionOptions.6">Connection Options</h3><pre>-h host | --host host</pre><p align="LEFT" style="margin-left: 30.0px;">The host name of the HAWQ master database server. If not specified, reads the name from the environment variable PGHOST or defaults to localhost.</p><pre>-p <em>port </em><span style="font-size: medium;"> </span>| --port port</pre><p style="margin-left: 30.0px;">The TCP port where the HAWQ master database server listens for connections. If not specified, reads the environment variable PGPORT, or defaults to 5432.</p><pre>-U username | --username username</pre><p style="margin-left: 30.0px;">The database role name to connect as. If not specified, reads from the environment variable PGUSER or defaults to the current system role name.</p><pre>-W | --password</pre><p style="margin-left: 30.0px;">Force a password prompt.</p><h3 id="ClientUtilityReference-Notes.1">Notes</h3><p align="LEFT">Since pg_dumpall calls pg_dump internally, some diagnostic messages refer to pg_dump</p><p align="LEFT">Once databases are restored, it is wise to run ANALYZE on each database so the query planner has useful statistics. You can also run vacuumdb -a -z to analyze all databases.</p><p>To restore or create databases in non-default locations while using pg_dumpall, check that you have all the necessary tablespace, filespace, and directories.</p><h3 id="ClientUtilityReference-Examples.5">Examples</h3><p align="LEFT">To dump all databases:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="theme: Confluence; brush: sql; gutter: false" style="font-size:12px;">pg_dumpall > db.out</pre>
</div></div><p><span style="font-size: medium;"><span style="font-size: medium;"><span style="color: rgb(19,73,255);font-size: small;"><span style="font-size: medium;"><span style="font-size: medium;"><span style="font-size: medium;"> </span></span></span></span></span></span>To reload this file:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="theme: Confluence; brush: sql; gutter: false" style="font-size:12px;">pg_dumpall > db.outpsql template1 -f db.out</pre>
</div></div><p>To dump only global objects (including filespaces and resource queues):</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="theme: Confluence; brush: sql; gutter: false" style="font-size:12px;">pg_dumpall -g -f -r</pre>
</div></div><h3 id="ClientUtilityReference-SeeAlso.6">See Also</h3><p>pg_dump</p><h2 id="ClientUtilityReference-pg_restore">pg_restore</h2><p>Restores a database from an archive file created by pg_dump.</p><h3 id="ClientUtilityReference-Synopsis.7">Synopsis</h3><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="theme: Confluence; brush: sql; gutter: false" style="font-size:12px;">pg_restore [connection_option ...] [restore_option ...]filename</pre>
</div></div><h3 id="ClientUtilityReference-Description.7">Description</h3><p>pg_restore is a utility for restoring a database from an archive created by pg_dump in non-plain-text formats. pg_restore reconstructs the database to the state it was in at the time it was saved. The archive files also allow pg_restore to be selective about what is restored, or even to reorder the items prior to being restored.</p><p align="LEFT">pg_restore can operate in two modes. If a database name is specified, the archive is restored directly into the database. Otherwise, a script containing the SQL commands necessary to rebuild the database is created and written to a file or to standard output. The script output is equivalent to the plain text output format of pg_dump. Some of the options controlling the output are therefore analogous to pg_dump options.</p><p align="LEFT">pg_restore cannot restore information that is not present in the archive file. For instance, if the archive was made using the “dump data as INSERT commands” option, pg_restore will not be able to load the data using COPY statements.</p><h3 id="ClientUtilityReference-Options.7">Options</h3><pre>filename</pre><p style="margin-left: 30.0px;">Specifies the location of the archive file to be restored. If not specified, the standard input is used.</p><pre>-a | --data-only</pre><p align="LEFT" style="margin-left: 30.0px;">Restore only the data, not the schema (data definitions).</p><pre>-c | --clean</pre><p align="LEFT" style="margin-left: 30.0px;">Clean (drop) database objects before recreating them.</p><pre>-C | --create</pre><p style="margin-left: 30.0px;">Creates the database before restoring it. When this option is used, the database named with -d is used only to issue the initial CREATE DATABASE command. All data is restored into the database name that appears in the archive.</p><pre>-d dbname <span> </span>| --dbname=dbname</pre><p style="margin-left: 30.0px;">Connects to this database and restores directly into this database. The default is to use the PGDATABASE environment variable setting, or the same name as the current system user.</p><pre>-e | --exit-on-error</pre><p style="margin-left: 30.0px;">Exits if an error is encountered while sending SQL commands to the database. The default is to continue and to display a count of errors at the end of the restoration.</p><p><span style="font-size: medium;"><span style="font-size: medium;"> </span></span><span style="line-height: 1.4285715;">-f outfilename | --file=outfilename</span></p><p style="margin-left: 30.0px;">Specifies output file for generated script, or for the listing when used with -l. Default is the standard output.</p><pre>-F t|c | --format=tar|custom</pre><p style="margin-left: 30.0px;">The format of the archive produced by<span style="font-size: medium;"><span style="font-size: medium;"> </span></span>pg_dump. It is not necessary to specify the format, since pg_restore will determine the format automatically. Format can be either tar or custom.</p><pre>-i | --ignore-version</pre><p style="margin-left: 30.0px;">Ignore database version checks.</p><pre>-l | --list</pre><p style="margin-left: 30.0px;">List the contents of the archive. The output of this operation can be used with the -L option to restrict and reorder the items that are restored.</p><pre>-L <em>list-file </em><span style="font-size: medium;"> </span>| --use-list=list-file</pre><p style="margin-left: 30.0px;">Restore elements in the order they appear in the <em>list-file </em><span style="font-size: small;"> </span>only. Lines can be moved and can also be commented out by placing a; at the start of the line.</p><pre>-n <em>schema </em><span style="font-size: medium;"> </span>| --schema=schema</pre><p align="LEFT" style="margin-left: 30.0px;">Restore only objects that are in the named schema. This can be combined with the -t option to restore just a specific table.</p><pre>-O | --no-owner</pre><p style="margin-left: 30.0px;">Do not output commands to set ownership of objects to match the original database.</p><p align="LEFT" style="margin-left: 30.0px;">By default, pg_restore issues ALTER OWNER or SET SESSION AUTHORIZATION statements to set ownership of created schema elements. These statements will fail unless you connect to the database as a superuser, or own the objects in the script. With -O, any user name can be used for the initial connection, and this user will own all the created objects.</p><pre>-P 'function-name (argtype [, ...])' |--function='function-name (argtype [, ...])'</pre><p style="margin-left: 30.0px;">Restore the named function only. The function name must be enclosed in quotes. Be careful to spell the function name and arguments exactly as they appear in the dump file’s table of contents (as shown by the --list option).</p><pre>-s | --schema-only</pre><p align="LEFT" style="margin-left: 30.0px;">Restore only the schema (data definitions), not the data (table contents). Sequence current values will not be restored, either. (Do not confuse this with the --schema option, which uses the word schema in a different meaning.)</p><pre>-S <em>username </em><span style="font-size: medium;"> </span>| --superuser=username</pre><p style="margin-left: 30.0px;">Specify the superuser user name to use when disabling triggers. This is only relevant if --disable-triggers is used.</p><pre>-t <em>table </em><span style="font-size: medium;"> </span>| --table=table</pre><p style="margin-left: 30.0px;">Restore definition and/or data of named table only.</p><pre>-T trigger | --trigger=trigger</pre><p style="margin-left: 30.0px;">Restore named trigger only.</p><pre>-v | --verbose</pre><p style="margin-left: 30.0px;">Specifies verbose mode.</p><pre>-x | --no-privileges | --no-acl</pre><p style="margin-left: 30.0px;">Prevent restoration of access privileges (GRANT/REVOKE commands).</p><pre>--disable-triggers</pre><p style="margin-left: 30.0px;">This option is only relevant when performing a data-only restore. It instructs pg_restore to execute commands to temporarily disable triggers on the target tables while the data is reloaded. Use this if you have triggers on the tables that you do not want to invoke during data reload. You must be superuser to issue the --disable-triggers command. So, you should also specify a superuser name with -S, or preferably run pg_restore as a superuser.</p><pre>--no-data-for-failed-tables</pre><p style="margin-left: 30.0px;">If the table already exists, the table data is restored even if the creation command for the table fails. This is the default. With this option, data for such a table is skipped.</p><p align="LEFT" style="margin-left: 30.0px;">This behavior is useful when the target database may already contain the desired table contents. Specifying this option prevents duplicate or obsolete data from being loaded. This option is effective only when restoring directly into a database, not when producing SQL script output.<span style="font-size: medium;"><span style="font-size: medium;"><span style="font-size: medium;"> </span></span></span></p><h3 id="ClientUtilityReference-ConnectionOptions.7">Connection Options</h3><pre>-h host | --host host</pre><p style="margin-left: 30.0px;">The host name of the HAWQ master database server. If not specified, reads the name from the environment variable PGHOST or defaults to localhost.</p><pre>-p <em>port </em><span style="font-size: medium;"> </span>| --port port</pre><p style="margin-left: 30.0px;">The TCP port where the HAWQ master database server listens for connections. If not specified, reads the environment variable PGPORT, or defaults to 5432.</p><p>-U <em>username </em><span style="font-size: medium;"> </span>| --username <em>username</em></p><p style="margin-left: 30.0px;">The database role name to connect as. If not specified, reads from the environment variable PGUSER, or defaults to the current system role name.</p><pre>-W | --password</pre><p style="margin-left: 30.0px;">Force a password prompt.</p><pre>-1 | --single-transaction</pre><p style="margin-left: 30.0px;">Execute the restore as a single transaction. This ensures that either all the commands complete successfully, or no changes are applied.</p><h3 id="ClientUtilityReference-Notes.2">Notes</h3><p align="LEFT">If your installation has any local additions to the template1 database, load the output of pg_restore into an empty database; otherwise you will see errors for duplicate definitions of the added objects. To make an empty database without any local additions, copy from template0, not template1, for example:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="theme: Confluence; brush: sql; gutter: false" style="font-size:12px;">CREATE DATABASE foo WITH TEMPLATE template0;</pre>
</div></div><p align="LEFT">When restoring data to a pre-existing table and the option --disable-triggers is used, pg_restore disables triggers on user tables before inserting the data, then re-enables them after the data is inserted. If the restore is stopped in the middle, the system catalogs could be left in the wrong state.</p><p align="LEFT">pg_restore will not restore large objects for a single table. If an archive contains large objects, then all large objects will be restored.</p><p align="LEFT">See also the pg_dump documentation for details on limitations of pg_dump.</p><p align="LEFT">Once restored, it is wise to run ANALYZE on each restored table so the query planner has useful statistics.</p><h3 id="ClientUtilityReference-Examples.6">Examples</h3><p>Assume we have dumped a database called mydb into a custom-format dump file:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="theme: Confluence; brush: sql; gutter: false" style="font-size:12px;">pg_dump -Fc mydb > db.dump</pre>
</div></div><p><span style="font-size: medium;"><span style="font-size: medium;"><span style="font-size: medium;"><span style="font-size: medium;"> </span></span></span></span>To drop the database and recreate it from the dump:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="theme: Confluence; brush: sql; gutter: false" style="font-size:12px;">dropdb mydb
pg_restore -C -d template1 db.dump</pre>
</div></div><p>To reload the dump into a new database called <em>newdb</em><span style="font-size: medium;"> </span>.</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="theme: Confluence; brush: sql; gutter: false" style="font-size:12px;">createdb -T template0 newdb
pg_restore -d newdb db.dump</pre>
</div></div><p style="margin-left: 30.0px;">Note: there is no -C, we instead connect directly to the database to be restored into. Also the new database uses template0, not template1, to ensure it is initially empty:</p><p>To reorder database items, it is first necessary to dump the table of contents of the archive:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="theme: Confluence; brush: sql; gutter: false" style="font-size:12px;">pg_restore -l db.dump > db.list</pre>
</div></div><p>The listing file consists of a header and one line for each item, for example,</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="theme: Confluence; brush: sql; gutter: false" style="font-size:12px;">; Archive created at Fri Jul 28 22:28:36 2006
; dbname: mydb
; TOC Entries: 74
; Compression: 0
; Dump Version: 1.4-0
; Format: CUSTOM
;
; Selected TOC Entries:
;
2; 145344 TABLE species postgres
3; 145344 ACL species
4; 145359 TABLE nt_header postgres
5; 145359 ACL nt_header
6; 145402 TABLE species_records postgres
7; 145402 ACL species_records
8; 145416 TABLE ss_old postgres
9; 145416 ACL ss_old
10; 145433 TABLE map_resolutions postgres
11; 145433 ACL map_resolutions
12; 145443 TABLE hs_old postgres
13; 145443 ACL hs_old</pre>
</div></div><p>Semicolons start a comment, and the numbers at the start of lines refer to the internal archive ID assigned to each item. Lines in the file can be commented out, deleted, and reordered. For example,</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="theme: Confluence; brush: sql; gutter: false" style="font-size:12px;">10; 145433 TABLE map_resolutions postgres
;2; 145344 TABLE species postgres
;4; 145359 TABLE nt_header postgres
6; 145402 TABLE species_records postgres
;8; 145416 TABLE ss_old postgres</pre>
</div></div><p>These lines could be used as input to pg_restore and would only restore items 10 and 6, in that order:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="theme: Confluence; brush: sql; gutter: false" style="font-size:12px;">pg_restore -L db.list db.dump</pre>
</div></div><h3 id="ClientUtilityReference-SeeAlso.7">See Also</h3><p>pg_dump</p><h2 id="ClientUtilityReference-psql">psql</h2><p>Interactive command-line interface for HAWQ.</p><h3 id="ClientUtilityReference-Synopsis.8">Synopsis</h3><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="theme: Confluence; brush: sql; gutter: false" style="font-size:12px;">psql [option...] [dbname [username]]</pre>
</div></div><h3 id="ClientUtilityReference-Description.8">Description</h3><p>psql is a terminal-based front-end to HAWQ. It enables you to type in queries interactively, issue them to HAWQ, and see the query results. Alternatively, input can be from a file. In addition, it provides a number of meta-commands and various shell-like features to facilitate writing scripts and automating a wide variety of tasks.</p><h3 id="ClientUtilityReference-Options.8">Options</h3><pre>-a | --echo-all</pre><p style="margin-left: 30.0px;">Prints all input lines to standard output as they are read. This is more useful for script processing rather than interactive mode.</p><pre>-A | --no-align</pre><p align="LEFT" style="margin-left: 30.0px;">Switches to unaligned output mode. (The default output mode is aligned.)</p><pre>-c 'command ' | --command 'command '</pre><p><span style="background-color: transparent;line-height: 1.4285715;">Specifies that psql is to execute the specified command string, and then exit. This is useful in shell scripts. </span><em style="background-color: transparent;line-height: 1.4285715;">command </em><span style="font-size: small;"> </span><span style="background-color: transparent;line-height: 1.4285715;">must be either a command string that is completely parseable by the server, or a single backslash command. Thus, you cannot mix SQL and psql meta-commands with this option. To achieve that, you could pipe the string into psql, for example:</span></p><p align="LEFT">echo '\x \\ SELECT * FROM foo;' | psql. (\\ is the separator meta-command.)</p><p>If the command string contains multiple SQL commands, they are processed in a single transaction, unless there are explicit BEGIN/COMMIT commands included in the string to divide it into multiple transactions. This is different from the behavior when the same string is fed to psql’s standard input.</p><p align="LEFT">-d dbname | --dbname <em>dbname</em></p><p>Specifies the name of the database to connect to. This is equivalent to specifying dbname as the first non-option argument on the command line.</p><p align="LEFT">If this parameter contains an equals sign, it is treated as a conninfo string; for example you can pass 'dbname=postgres user=username password=mypass' as dbname.</p><p>-e | --echo-queries</p><p>Copies all SQL commands sent to the server to standard output as well.</p><p>-E | --echo-hidden</p><p>Echoes the actual queries generated by \d and other backslash commands. You can use this to study psql’s internal operations.</p><p align="LEFT">-f <em>filename </em><span style="font-size: medium;"> </span>| --file <em>filename</em></p><p>Uses a file as the source of commands instead of reading commands interactively.</p><p align="LEFT">After the file is processed, psql terminates. If <em>filename </em><span style="font-size: small;"> </span>is - (hyphen), then standard input is read. Using this option is subtly different from writing psql < filename. In general, both will do what you expect, but using -f enables some useful features such as error messages with line numbers.</p><p align="LEFT">-F <em>separator </em><span style="font-size: medium;"> </span>| --field-separator <em>separator</em></p><p>Uses the specified separator as the field separator for unaligned output.</p><p align="LEFT">-H | --html</p><p>Turns on HTML tabular output.</p><p align="LEFT">-l | --list</p><p>Lists all available databases, then exits. Other non-connection options are ignored.</p><p align="LEFT">-L <em>filename </em><span style="font-size: medium;"> </span>| --log-file <em>filename</em></p><p align="LEFT"><span style="background-color: transparent;line-height: 1.4285715;">Writes all query output into the specified log file, in addition to the normal output destination.</span></p><p align="LEFT">-o <em>filename </em><span style="font-size: medium;"> </span>| --output <em>filename</em></p><p align="LEFT"><span style="background-color: transparent;line-height: 1.4285715;">Puts all query output into the specified file.</span></p><p align="LEFT">-P <em>assignment </em><span style="font-size: medium;"> </span>| --pset <em>assignment</em></p><p align="LEFT"><span style="background-color: transparent;line-height: 1.4285715;">Allows you to specify printing options in the style of \pset on the command line.</span></p><p align="LEFT" style="margin-left: 30.0px;">Note that here you must separate name and value with an equal sign instead of a space. Thus, to set the output format to LaTeX, you could write -P format=latex.</p><pre>-q | --quiet</pre><p align="LEFT" style="margin-left: 30.0px;">Specifies that psql 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 -c option.</p><pre>-R <em>separator </em><span style="font-size: medium;"> </span>| --record-separator separator</pre><p style="margin-left: 30.0px;">Uses <em>separator </em><span style="font-size: small;"> </span>as the record separator for unaligned output.</p><pre>-s | --single-step</pre><p style="margin-left: 30.0px;">Runs in single-step mode. That means the user is prompted before each command is sent to the server, with the option to also cancel execution. Use this to debug scripts.</p><pre>-S | --single-line</pre><p style="margin-left: 30.0px;">Runs in single-line mode, where a new line terminates an SQL command, as a semicolon does.</p><pre>-t | --tuples-only</pre><p style="margin-left: 30.0px;">Turns off printing of column names and result row count footers, etc. This command is equivalent to \pset tuples_only and is provided for convenience.</p><pre>-T <em>table_options </em><span style="font-size: medium;"> </span>| --table-attr table_options</pre><p style="margin-left: 30.0px;">Allows you to specify options to be placed within the HTML table tag. See \pset for details.</p><p align="LEFT">-v <em>assignment </em><span style="font-size: medium;"> </span>| --set <em>assignment </em><span style="font-size: medium;"> </span>| --variable <em>assignment</em></p><p style="margin-left: 30.0px;">Performs a variable assignment, like the \set internal 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 just set a variable without a value, use the equal sign but leave off the value. These assignments are done during a very early stage of start-up, so variables reserved for internal purposes might get overwritten later.</p><pre>-V | --version</pre><p style="margin-left: 30.0px;">Prints the psql version and exit.</p><pre>-x | --expanded</pre><p style="margin-left: 30.0px;">Turns on the expanded table formatting mode.</p><pre>-X | --no-psqlrc</pre><p style="margin-left: 30.0px;">Does not read the start-up file (neither the system-wide psqlrc file nor the user’s ~/.psqlrc file).</p><pre>-1 | --single-transaction</pre><p align="LEFT" style="margin-left: 30.0px;">When psql executes a script with the -f option, adding this option wraps BEGIN/COMMIT around the script to execute it as a single transaction. This ensures that either all the commands complete successfully, or no changes are applied.</p><p align="LEFT" style="margin-left: 30.0px;">If the script itself uses BEGIN, COMMIT, or ROLLBACK, this option will not have the desired effects. Also, if the script contains any command that cannot be executed inside a transaction block, specifying this option will cause that command (and hence the whole transaction) to fail.</p><pre>-? | --help</pre><p style="margin-left: 30.0px;">Shows help about psql command line arguments, and exits.</p><p><span style="font-size: medium;"><span style="font-size: medium;"> </span></span></p><h3 id="ClientUtilityReference-ConnectionOptions.8">Connection Options</h3><pre>-h host <span> </span>| --host host</pre><p style="margin-left: 30.0px;">The host name of the HAWQ master database server. If not specified, reads the name from the environment variable PGHOST or defaults to localhost.</p><pre>-p port <span> </span>| --port port</pre><p style="margin-left: 30.0px;">The TCP port where the HAWQ master database server listens for connections. If not specified, reads the environment variable PGPORT, or defaults to 5432.</p><pre>-U username <span> </span>| --username username</pre><p style="margin-left: 30.0px;">The database role name to connect as. If not specified, reads from the environment variable PGUSER or defaults to the current system role name.</p><pre>-W | --password</pre><p style="margin-left: 30.0px;">Pivotal recommends using this option to force a password prompt. If no password prompt is issued and the server requires password authentication, the connection attempt will fail.</p><pre>-w | --no-password</pre><p style="margin-left: 30.0px;">Does not issue a password prompt. If the server requires password authentication, storing the password a .pgpass file ensures a successful connection when running batch jobs and scripts.</p><p style="margin-left: 30.0px;"><strong>Note</strong>: This option remains set for the entire session, and so it affects uses of the meta-command \connect as well as the initial connection attempt.</p><h3 id="ClientUtilityReference-ExitStatus">Exit Status</h3><p>psql returns the following values:</p><p align="LEFT">0 to the shell if it finished normally.</p><p align="LEFT">1 if a psql fatal error (out of memory, file not found) occurs.</p><p align="LEFT">2 if the connection to the server went bad and the session was not interactive.</p><p>3 if an error occurred in a script and the variable ON_ERROR_STOP was set.</p><h3 id="ClientUtilityReference-Usage">Usage</h3><h4 id="ClientUtilityReference-ConnectingToADatabase">Connecting To A Database</h4><p>psql is a client application for HAWQ. To connect to a database you need to know the following information:</p><ul><li>Name of your target database</li><li>Host name and port number of the HAWQ master server</li><li>Database user name</li></ul><p align="LEFT">Those parameters can be communicated to psql via command line options, namely -d, -h, -p, and -U respectively. If an argument is found that does not belong to any option, it is interpreted as the database name (or the user name, if the database name is already given). Not all these options are required; there are useful defaults. If you omit the host name, psql will connect via a UNIX-domain socket to a master server on the local host, or via TCP/IP to localhost on machines that do not have UNIX-domain sockets. The default master port number is 5432. If you use a different port for the master, you must specify the port. The default database user name is your UNIX user name, as is the default database name. Note that you cannot just connect to any database under any user name. Your database administrator should have informed you about your access rights.</p><p align="LEFT">When the defaults are not right, you can save yourself some typing by setting any or all of the environment variables PGAPPNAME, PGDATABASE, PGHOST, PGPORT, and PGUSER to appropriate values.</p><p align="LEFT">It is also convenient to have a ~/.pgpass file to avoid regularly having to type in passwords. This file should reside in your home directory and contain lines of the following format for the hostname:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="theme: Confluence; brush: sql; gutter: false" style="font-size:12px;">port:database:username:password</pre>
</div></div><p align="LEFT">The permissions on .pgpass must disallow any access to world or group (for example: chmod 0600 ~/.pgpass). If the permissions are less strict than this, the file will be ignored. The file permissions are not currently checked on Microsoft Windows clients.</p><p align="LEFT">If the connection could not be made due to insufficient privileges, or if the server is not running, psql will return an error and terminate.</p><h4 id="ClientUtilityReference-EnteringSQLCommands">Entering SQL Commands</h4><p align="LEFT">In normal operation, psql provides a prompt with the name of the database to which psql is currently connected, followed by the string <strong>=> </strong><span style="font-size: small;"> </span>for a regular user or <strong>=# </strong><span style="font-size: small;"> </span>for a superuser. For example:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="theme: Confluence; brush: sql; gutter: false" style="font-size:12px;">testdb=>
testdb=#</pre>
</div></div><p align="LEFT">At the prompt, the user can type in SQL 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.</p><h3 id="ClientUtilityReference-Meta-Commands">Meta-Commands</h3><p>Anything you enter in psql that begins with an unquoted backslash is a psql meta-command that is processed by psql itself. These commands help make psql more useful for administration or scripting. Meta-commands are more commonly called slash or backslash commands.</p><p align="LEFT">The format of a psql 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.</p><p align="LEFT">To include whitespace into an argument, quote it with a single quote. To include a single quote into such an argument, use two single quotes. Anything contained in single quotes is further subject to C-like substitutions for \n (new line), \t (tab), \digits (octal), and \xdigits (hexadecimal).</p><p align="LEFT">If an unquoted argument begins with a colon (:), it is taken as a psql variable and the value of the variable is used as the argument instead.</p><p>Arguments that are enclosed in backquotes (`) are taken as a command line that is passed to the shell. The output of the command (with any trailing newline removed) is taken as the argument value. The above escape sequences also apply in backquotes.</p><p align="LEFT">Some commands take an SQL identifier (such as a table name) as argument. These arguments follow the syntax rules of SQL: Unquoted letters are forced to lowercase, while double quotes (") 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, FOO"BAR"BAZ is interpreted as fooBARbaz, and "A weird"" name" becomes A weird" name.</p><p align="LEFT">Parsing for arguments stops when another unquoted backslash occurs. This is taken as the beginning of a new meta-command. The special sequence \\ (two backslashes) marks the end of arguments and continues parsing SQL commands, if any. That way SQL and psql 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. The following meta-commands are defined:</p><pre>\a</pre><p style="margin-left: 30.0px;">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 \pset for a more general solution.</p><pre>\cd [directory<span style="font-size: medium;"> </span>]</pre><p style="margin-left: 30.0px;">Changes the current working directory. Without argument, changes to the current user’s home directory. To print your current working directory, use \!pwd.</p><pre>\C [title<span style="font-size: medium;"> </span>]</pre><p style="margin-left: 30.0px;">Sets the title of any tables being printed as the result of a query or unsets any such title. This command is equivalent to \pset title.</p><pre>\c | \connect [dbname [username ] [host ] [port ]]</pre><p style="margin-left: 30.0px;">Establishes a new connection. If the new connection is successfully made, the previous connection is closed. If any of dbname, username, host or port are omitted, the value of that parameter from the previous connection is used. If the connection attempt failed, the previous connection will only be kept if psql is in interactive mode. When executing a non-interactive script, processing will immediately stop with an error. This distinction was chosen as a user convenience against typos, and a safety mechanism that scripts are not accidentally acting on the wrong database.</p><pre>\conninfo</pre><p style="margin-left: 30.0px;">Displays information about the current connection including the database name, the user name, the type of connection (UNIX domain socket, TCP/IP, etc.), the host, and the port.</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="theme: Confluence; brush: sql; gutter: false" style="font-size:12px;">\copy {table [(column_list)] | (query)}{from | to} {filename | stdin | stdout | pstdin | pstdout}[with] [binary] [oids] [delimiter [as] 'character'][null [as] 'string'] [csv [header][quote [as] 'character'] [escape [as] 'character'][force quote column_list] [force not null column_list]]</pre>
</div></div><p style="margin-left: 30.0px;">Performs a frontend (client) copy. This is an operation that runs an SQL COPY command, but instead of the server reading or writing the specified file, psql reads or writes the file and routes the data between the server and the local file system. This means that file accessibility and privileges are those of the local user, not the server, and no SQL superuser privileges are required.</p><p style="margin-left: 30.0px;">The syntax of the command is similar to that of the SQL COPY command. Note that, because of this, special parsing rules apply to the \copy command. In particular, the variable substitution rules and backslash escapes do not apply.</p><p align="LEFT" style="margin-left: 30.0px;">\copy ... from stdin | to stdout reads/writes based on the command input and output respectively. All rows are read from the same source that issued the command, continuing until \. is read or the stream reaches EOF. Output is sent to the same place as command output. To read/write from psql’s standard input or output, use pstdin or pstdout. This option is useful for populating tables in-line within a SQL script file.</p><p align="LEFT" style="margin-left: 30.0px;">This operation is not as efficient as the SQL COPY command because all data must pass through the client/server connection.</p><pre>\copyright </pre><p style="margin-left: 30.0px;">Shows the copyright and distribution terms of PostgreSQL on which HAWQ is based.</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="theme: Confluence; brush: sql; gutter: false" style="font-size:12px;">\d [relation_pattern] |
\d+ [relation_pattern] |
\dS [relation_pattern]</pre>
</div></div><p style="margin-left: 30.0px;">For each relation (table, external table, view, or sequence) matching the relation pattern, show all columns, their types, the tablespace (if not the default) and any special attributes such as NOT NULL or defaults, if any. Associated constraints, rules, and triggers are also shown, as is the view definition if the relation is a view.</p><ul><li style="list-style-type: none;background-image: none;"><ul><li>The command form \d+ is identical, except that more information is displayed: any comments associated with the columns of the table are shown, as is the presence of OIDs in the table.</li><li>The command form \dS is identical, except that system information is displayed as well as user information.</li></ul></li></ul><p align="LEFT" style="margin-left: 30.0px;">For example, \dt displays user tables, but not system tables; \dtS displays both user and system tables. Both these commands can take the + parameter to display additional information, as in \dt+ and \dtS+.</p><p style="margin-left: 30.0px;">If \d is used without a pattern argument, it is equivalent to \dtvs which will show a list of all tables, views, and sequences.</p><pre>\da [aggregate_pattern<span> </span>]</pre><p style="margin-left: 30.0px;">Lists all available aggregate functions, together with the data types they operate on. If a pattern is specified, only aggregates whose names match the pattern are shown.</p><pre>\db [tablespace_pattern<span style="font-size: medium;"> </span>] | \db+ [<em>tablespace_pattern</em><span style="font-size: medium;"> </span>]</pre><p style="margin-left: 30.0px;">Lists all available tablespaces and their corresponding filespace locations. If pattern is specified, only tablespaces whose names match the pattern are shown. If + is appended to the command name, each object is listed with its associated permissions.</p><pre>\dc [conversion_pattern<span style="font-size: medium;"> </span>]</pre><p style="margin-left: 30.0px;">Lists all available conversions between character-set encodings. If pattern is specified, only conversions whose names match the pattern are listed.</p><pre>\dC</pre><p style="margin-left: 30.0px;">Lists all available type casts.</p><pre>\dd [object_pattern<span style="font-size: medium;"> </span>]</pre><p style="margin-left: 30.0px;">Lists all available objects. If pattern is specified, only matching objects are shown.</p><pre>\dD [domain_pattern<span style="font-size: medium;"> </span>]</pre><p style="margin-left: 30.0px;">Lists all available domains. If pattern is specified, only matching domains are shown.</p><pre>\df [<em>function_pattern</em><span style="font-size: medium;"> </span>] | \df+ [function_pattern <span style="font-size: medium;"> </span>]</pre><p style="margin-left: 30.0px;">Lists available functions, together with their argument and return types. If pattern is specified, only functions whose names match the pattern are shown. If the form \df+is used, additional information about each function, including language and description, is shown. To reduce clutter, \df does not show data type I/O functions. This is implemented by ignoring functions that accept or return type cstring.</p><pre>\dg [role_pattern<span style="font-size: medium;"> </span>]</pre><p style="margin-left: 30.0px;">Lists all database roles. If pattern is specified, only those roles whose names match the pattern are listed.</p><pre>\distPvxS [<em>sequence </em><span style="font-size: medium;"> </span>| <em>table </em><span style="font-size: medium;"> </span>| <em>parent table </em><span style="font-size: medium;"> </span>| <em>view </em><span style="font-size: medium;"> </span>| external_table | system_object<span style="font-size: medium;"> </span>]</pre><p style="margin-left: 30.0px;">This is not the actual command name: the letters s, t, P, v, x, S stand for sequence, table, parent table, view, external table, and system table, respectively. You can specify any or all of these letters, in any order, to obtain a listing of all the matching objects. The letter S restricts the listing to system objects; without S, only non-system objects are shown. If + is appended to the command name, each object is listed with its associated description, if any. If a pattern is specified, only objects whose names match the pattern are listed.</p><pre>\dl</pre><p align="LEFT" style="margin-left: 30.0px;">This is an alias for \lo_list, which shows a list of large objects.</p><pre><span style="font-size: medium;"><span style="font-size: medium;"> </span></span>\dn [<em>schema_pattern</em><span style="font-size: medium;"> </span>] | \dn+ [<em>schema_pattern</em><span style="font-size: medium;"> </span>]</pre><p style="margin-left: 30.0px;">Lists all available schemas (namespaces). If pattern is specified, only schemas whose names match the pattern are listed. Non-local temporary schemas are suppressed. If + is appended to the command name, each object is listed with its associated permissions and description, if any.</p><pre>\do [operator_pattern<span style="font-size: medium;"> </span>]</pre><p style="margin-left: 30.0px;">Lists available operators with their operand and return types. If pattern is specified, only operators whose names match the pattern are listed.</p><pre>\dp [relation_pattern_to_show_privileges<span style="font-size: medium;"> </span>]</pre><p style="margin-left: 30.0px;">Produces a list of all available tables, views, and sequences, with their associated access privileges. If pattern is specified, only tables, views, and sequences whose names match the pattern are listed. The GRANT and REVOKE commands are used to set access privileges.</p><pre>\dT [<em>datatype_pattern</em><span style="font-size: medium;"> </span>] | \dT+ [<em>datatype_pattern</em><span style="font-size: medium;"> </span>]</pre><p style="margin-left: 30.0px;">Lists all data types or only those that match pattern. The command form \dT+ shows extra information.</p><pre>\du [<em>role_pattern</em><span style="font-size: medium;"> </span>]</pre><p style="margin-left: 30.0px;">Lists all database roles, or only those that match pattern.</p><pre>\e | \edit [filename<span style="font-size: medium;"> </span>]</pre><p style="margin-left: 30.0px;">If a file name is specified, the file is edited; after the editor exits, its content is copied back to the query buffer. If no argument is given, the current query buffer is copied to a temporary file, which is then edited in the same fashion. The new query buffer is then re-parsed according to the normal rules of psql, where the whole buffer is treated as a single line. (Thus you cannot make scripts this way. Use \i to create scripts.) This means also that if the query ends with (or rather contains) a semicolon, it is immediately executed. In other cases, it will merely wait in the query buffer. psql searches the environment variables PSQL_EDITOR, EDITOR, and VISUAL (in that order) for an editor to use. If all of them are unset, vi is used on UNIX systems, notepad.exe on Windows systems.</p><pre>\echo text <span style="font-size: medium;"> </span>[ ... ]</pre><p style="margin-left: 30.0px;">Prints the arguments to the standard output, separated by one space and followed by a newline. This can be useful to intersperse information in the output of scripts. If you use the \o command to redirect your query output, you may wish to use \qecho instead of this command.</p><pre>\encoding [encoding<span> </span>]</pre><p style="margin-left: 30.0px;">Sets the client character set encoding. Without an argument, this command shows the current encoding.</p><pre>\f [<em>field_separator_string</em><span style="font-size: medium;"> </span>]</pre><p style="margin-left: 30.0px;">Sets the field separator for unaligned query output. The default is the vertical bar (|). See also \pset for a generic way of setting output options.</p><pre>\g [{<em>filename </em><span style="font-size: medium;"> </span>| |command <span style="font-size: medium;"> </span>}]</pre><p style="margin-left: 30.0px;">Sends the current query input buffer to the server and optionally stores the query’s output in a file or pipes the output into a separate UNIX shell executing command. A bare \g is virtually equivalent to a semicolon. A \g with argument is a one-shot alternative to the \o command.</p><pre>\h | \help [sql_command<span style="font-size: medium;"> </span>]</pre><p style="margin-left: 30.0px;">Gives syntax help on the specified SQL command. If a command is not specified, then psql will list all the commands for which syntax help is available. Use an asterisk (*) to show syntax help on all SQL commands. To simplify typing, commands that consists of several words do not have to be quoted.</p><pre>\H</pre><p style="margin-left: 30.0px;">Turns on HTML query output format. If the HTML format is already on, it is switched back to the default aligned text format. This command is for compatibility and convenience; see \pset about setting other output options.</p><pre>\I input_filename</pre><p align="LEFT" style="margin-left: 30.0px;">Reads input from a file and executes it as though it had been typed on the keyboard. If you want to see the lines on the screen as they are read, you must set the variable ECHO for all files.</p><pre>\l | \list | \l+ | \list+</pre><p style="margin-left: 30.0px;">Lists the names, owners, and character set encodings of all the databases in the server. If + is appended to the command name, database descriptions are also displayed.</p><pre>\lo_export oid filename</pre><p style="margin-left: 30.0px;">Reads the large object with OID <em>loid </em><span style="font-size: small;"> </span>from the database and writes it to <em>filename</em><span style="font-size: small;"> </span>.</p><p style="margin-left: 30.0px;">Note that this is subtly different from the server function lo_export, which acts with the permissions of the user that the database server runs as and on the server’s file system. Use \lo_list to find out the large object’s OID.</p><pre>\lo_import large_object_filename <span style="font-size: medium;"> </span>[<em>comment</em><span style="font-size: medium;"> </span>]</pre><p style="margin-left: 30.0px;">Stores the file into a large object. Optionally, it associates the given comment with the object. Example:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="theme: Confluence; brush: sql; gutter: false" style="font-size:12px;">mydb=> \lo_import '/home/gpadmin/pictures/photo.xcf' 'a
picture of me'
lo_import 152801</pre>
</div></div><p style="margin-left: 30.0px;">The response indicates that the large object received object ID 152801; which should be saved, if you need to access the object ever again. For that reason, we recommend always associate a human-readable comment with every object. Those can then be seen with the \lo_list command. Note that this command is subtly different from the server-side lo_import because it acts as the local user on the local file system, rather than as the server’s user and file system.</p><pre>\lo_list</pre><p style="margin-left: 30.0px;">Shows a list of all large objects currently stored in the database, along with any comments provided for them.</p><pre>\lo_unlink largeobject_oid</pre><p style="margin-left: 30.0px;">Deletes the large object of the specified OID from the database. Use \lo_list to find out the large object’s OID.</p><pre>\o [ {query_result_filename <span style="font-size: medium;"> </span>| <em>|command</em><span style="font-size: medium;"> </span>} ]</pre><p style="margin-left: 30.0px;">Saves future query results to a file or pipes them into a UNIX shell command. If no arguments are specified, the query output will be reset to the standard output. Query results include all tables, command responses, and notices obtained from the database server, as well as output of various backslash commands that query the database (such as \d), but not error messages. To intersperse text output in between query results, use \qecho.</p><pre>\p</pre><p style="margin-left: 30.0px;">Prints the current query buffer to the standard output.</p><pre>\password [username<span> </span>]</pre><p style="margin-left: 30.0px;">Changes the password of the specified user (by default, the current user). This command prompts for the new password, encrypts it, and sends it to the server as an ALTER ROLE command. This makes sure that the new password does not appear in cleartext in the command history, the server log, or elsewhere.</p><pre>\prompt [ text ] name</pre><p style="margin-left: 30.0px;">Prompts the user to set a variable <em>name</em><span style="font-size: medium;"> </span>. Optionally, you can specify a prompt. Enclose prompts longer than one word in single quotes. By default, \prompt uses the terminal for input and output. However, use the -f command line switch to specify standard input and standard output.</p><pre>\pset print_option <span style="font-size: medium;"> </span>[<em>value</em><span style="font-size: medium;"> </span>]</pre><p align="LEFT" style="margin-left: 30.0px;">This command sets options affecting the output of query result tables. print_option describes which option is to be set. Adjustable printing options are:</p><ul><li>format<span style="font-size: medium;"> </span>– Sets the output format to one of <strong>u</strong><span style="font-size: small;"> </span>naligned, <strong>a</strong><span style="font-size: small;"> </span>ligned, <strong>h</strong><span style="font-size: small;"> </span>tml, latex, <strong>t</strong><span style="font-size: small;"> </span>roff-ms, or <strong>w</strong><span style="font-size: small;"> </span>rapped. First letter abbreviations are allowed. Unaligned writes all columns of a row on a line, separated by the currently active field separator. This is intended to create output that could be read in by other programs. Aligned mode is the standard, human-readable, nicely formatted text output that is the default. The HTML and LaTeX modes put out tables intended to be included in documents using the appropriate mark-up language. They are not complete documents! (This might not be so dramatic in HTML, but in LaTeX you must have a complete document wrapper.)</li></ul><p style="margin-left: 30.0px;"> The wrapped option sets the output format like the aligned parameter, but wraps wide data values across lines to make the output fit in the target column width. The target width is set with the columns option. To specify the column width and select the wrapped format, use two \pset commands; for example,to set the with to 72 columns and specify wrapped format, use the <br/> commands\pset columns 72 and then \pset format wrapped.</p><p style="margin-left: 30.0px;"> <strong>Note</strong>: Since psql does not attempt to wrap column header titles, the wrapped format behaves the same as aligned as if the total width needed for column headers exceeds the target.</p><ul><li>border<span style="font-size: medium;"> </span>– The second argument must be a number. In general, the higher the number the more borders and lines the tables will have, but this depends on the particular format. In HTML mode, this will translate directly into the border=...attribute, in the others only values 0 (no border), 1 (internal dividing lines), and 2 (table frame) make sense.</li><li>columns<span style="font-size: medium;"> </span>– Sets the target width for the wrapped format, and also the width limit for determining whether output is wide enough to require the pager. The default is <em>zero</em><span style="font-size: medium;"> </span>. Zero causes the target width to be controlled by the environment variable COLUMNS, or the detected screen width if COLUMNS is not set. In addition, if columns is zero then the wrapped format affects screen output only. If columns is nonzero then file and pipe output is wrapped to that width as well.</li></ul><p style="margin-left: 30.0px;"> After setting the target width, use the command \pset format wrapped to enable the wrapped format.</p><ul><li>expanded | x<span style="font-size: medium;"> </span>) – Toggles between regular and expanded format. When expanded format is enabled, query results are displayed in two columns, with the column name on the left and the data on the right. This mode is useful if the data would not fit on the screen in the normal horizontal mode. Expanded mode is supported by all four output formats.</li><li>linestyle [unicode | ascii | old-ascii] – Sets the border line drawing style to one of unicode, ascii, or old-ascii. Unique abbreviations, including one letter, are allowed for the three styles. The default setting is ascii . This option only affects the aligned and wrapped output formats.</li><li style="margin-left: 30.0px;"> ascii – uses plain ASCII characters. Newlines in data are shown using a + symbol in the right-hand margin. When the wrapped format wraps data from one line to the next without a newline <span style="background-color: transparent;line-height: 1.4285715;">character, a dot (.) is shown in the right-hand margin of the first line, and again in the left-hand margin of the following line.</span></li><li style="margin-left: 30.0px;"> old-ascii – style uses plain ASCII characters, using the formatting style used in PostgreSQL 8.4 and earlier. Newlines in data are shown using a : symbol in place of the left-hand column separator.</li></ul><p style="margin-left: 60.0px;"> When the data is wrapped from one line to the next without a newline character, a ; symbol is used in place of the left-hand column separator.</p><ul><li style="margin-left: 30.0px;"> unicode – style uses Unicode box-drawing characters. Newlines in data are shown using a carriage return symbol in the right-hand margin. When the data is wrapped from one line to the next</li></ul><p style="margin-left: 60.0px;"> without a newline character, an ellipsis symbol is shown in the right-hand margin of the first line, and again in the left-hand margin of the following line.</p><p style="margin-left: 30.0px;"> When the border setting is greater than zero, this option also determines the characters with which the border lines are drawn. Plain ASCII characters work everywhere, but Unicode characters look nicer on displays that recognize them.</p><ul><li>null 'string'<span style="font-size: medium;"> </span>– The second argument is a string to print whenever a column is null. The default is not to print anything, which can easily be mistaken for an empty string. For example, the command \pset null '(empty)' displays <em>(empty) </em><span style="font-size: medium;"> </span>in null columns.</li><li>fieldsep<span style="font-size: medium;"> </span>– Specifies the field separator to be used in unaligned output mode. That way, one can create, for example, tab- or comma-separated output, which other programs might prefer. To set a tab as field separator, type \pset fieldsep '\t'. The default field separator is '|' (a vertical bar).</li><li>footer<span style="font-size: medium;"> </span>– Toggles the display of the default footer (<em>x </em><span style="font-size: small;"> </span>rows).</li><li>numericlocal<span style="font-size: medium;">e</span><span style="font-size: medium;"> </span>– Toggles the display of a locale-aware character to separate groups of digits to the left of the decimal marker. It also enables a locale-aware decimal marker.</li><li>recordsep<span style="font-size: medium;"> </span>– Specifies the record (line) separator to use in unaligned output mode. The default is a newline character.</li><li>title [<em>text</em><span style="font-size: medium;"> </span>]<span style="font-size: medium;"> </span>– Sets the table title for any subsequently printed tables. This can be used to give your output descriptive tags. If no argument is given, the title is unset.</li><li>tableattr | T [<em>text</em><span style="font-size: medium;"> </span>]<span style="font-size: medium;"> </span>– Allows you to specify any attributes to be placed inside the HTML table tag. For example, this could be cellpadding or bgcolor. Note that you probably don’t want to specify border here, as that is already taken care of by \pset border.</li><li>tuples_only | t [no value | on | off]<span style="font-size: medium;"> </span>– By itself, the \pset tuples_only command toggles between tuples only and full display. The values <em>on </em>and <em>off </em><span style="font-size: medium;"> </span>set the tuples display, regardless of the current setting. Full display may show extra information such as column headers, titles, and various footers. In tuples only mode, only actual table data is shown The \t command is equivalent to \pset tuples_only and is provided for convenience.</li><li>pager<span style="font-size: medium;"> </span>– Controls the use of a pager for query and psql help output. When on, if the environment variable PAGER is set, the output is piped to the specified program. Otherwise a platform-dependent default (such as "more") is used. When off, the pager is not used. When on, the pager is used only when appropriate. Pager can also be set to always, which causes the pager to be always used.</li></ul><pre>\q</pre><p style="margin-left: 30.0px;">Quits the psql program.</p><pre>\qecho text [ ... ]</pre><p style="margin-left: 30.0px;">This command is identical to \echo except that the output will be written to the query output channel, as set by \o.</p><pre>\r</pre><p style="margin-left: 30.0px;">Resets (clears) the query buffer.</p><pre>\s [history_filename<span style="font-size: medium;"> </span>]</pre><p style="margin-left: 30.0px;">Print or save the command line history to <em>filename</em><span style="font-size: small;"> </span>. If <em>filename </em><span style="font-size: small;"> </span>is omitted, the history is written to the standard output.</p><pre>\set [name [value [ ... ]]]</pre><p style="margin-left: 30.0px;">Sets the internal variable <em>name </em><span style="font-size: small;"> </span>to <em>value </em><span style="font-size: small;"> </span>or, if more than one value is given, to the concatenation of all of them. If no second argument is given, the variable is just set with no value. To unset a variable, use the \unset command.</p><p style="margin-left: 30.0px;">Valid variable names can contain characters, digits, and underscores. Variable names are case-sensitive.</p><p style="margin-left: 30.0px;">Although you are welcome to set any variable to anything you want, psql treats several variables as special. They are documented in the section about variables. This command is totally separate from the SQL command SET.</p><pre>\t [no value | on | off]</pre><p style="margin-left: 30.0px;">The \t command by itself toggles a display of output column name headings and row count footer. The values <em>on </em><span style="font-size: medium;"> </span>and <em>off </em><span style="font-size: medium;"> </span>set the tuples display, regardless of the current setting. This command is equivalent to \pset tuples_only and is provided for convenience.</p><pre>\T table_options</pre><p style="margin-left: 30.0px;">Allows you to specify attributes to be placed within the table tag in HTML tabular output mode.</p><pre>\timing [no value | on | off]</pre><p style="margin-left: 30.0px;">The \timing command by itself toggles a display of how long each SQL statement takes, in milliseconds. The values <em>on </em><span style="font-size: medium;"> </span>and <em>off </em><span style="font-size: medium;"> </span>set the time display, regardless of the current setting.</p><p>\w {<em>filename </em><span style="font-size: medium;"> </span>| <em>|command</em><span style="font-size: medium;"> </span>}</p><p align="LEFT" style="margin-left: 30.0px;">Outputs the current query buffer to a file or pipes it to a UNIX command.</p><pre>\x</pre><p style="margin-left: 30.0px;">Toggles expanded table formatting mode.</p><pre>\z [relation_to_show_privileges<span style="font-size: medium;"> </span>]</pre><p style="margin-left: 30.0px;">Produces a list of all available tables, views and sequences with their associated access privileges. If a pattern is specified, only tables, views and sequences whose names match the pattern are listed. This is an alias for \dp.</p><pre>\! [command<span style="font-size: medium;"> </span>]</pre><p style="margin-left: 30.0px;">Escapes to a separate UNIX shell or executes the UNIX command. The arguments are not further interpreted, the shell will see them as is.</p><pre>\?</pre><p style="margin-left: 30.0px;">Shows help information about the psql backslash commands.</p><h3 id="ClientUtilityReference-Patterns">Patterns</h3><p align="LEFT">The various \d commands accept a pattern parameter to specify the object name(s) to be displayed. In the simplest case, a pattern is just the exact name of the object. The characters within a pattern are normally folded to lower case, just as in SQL names; for example, \dt FOO will display the table named foo. As in SQL names, placing double quotes around a pattern stops folding to lower case. Should you need to include an actual double quote character in a pattern, write it as a pair of double quotes within a double-quote sequence; again, this is in accord with the rules for SQL quoted identifiers. For example, \dt "FOO""BAR" will display the table named FOO"BAR (not foo"bar). Unlike the normal rules for SQL names, you can put double quotes around just part of a pattern, for instance \dt FOO"FOO"BAR will display the table named fooFOObar</p><p>Within a pattern, * matches any sequence of characters (including no characters) and ? matches any single character. (This notation is comparable to UNIX shell file name patterns.) For example, \dt int* displays all tables whose names begin with int.</p><p>But within double quotes, * and ? lose these special meanings and are just matched literally.</p><p align="LEFT">A pattern that contains a dot (.) is interpreted as a schema name pattern followed by an object name pattern. For example, \dt foo*.bar* displays all tables whose table name starts with bar that are in schemas whose schema name starts with foo. When no dot appears, then the pattern matches only objects that are visible in the current schema search path. Again, a dot within double quotes loses its special meaning and is matched literally.<span style="font-size: medium;"><span style="font-size: medium;"> </span></span></p><p align="LEFT">Advanced users can use regular-expression notations. All regular expression special characters work as specified in the PostgreSQL documentation on regular expressions, except for . , which is taken as a separator as mentioned above; * , which is translated to the regular-expression notation .*, and ? , which is translated to . . You can emulate these pattern characters at need by writing ? for ., (R+|) for R*, or (R|) for R?.</p><p>Remember that the pattern must match the whole name, unlike the usual interpretation of regular expressions; write * at the beginning and/or end if you don’t wish the pattern to be anchored. Note that within double quotes, all regular expression special characters lose their special meanings and are matched literally. Also, the regular expression special characters are matched literally in operator name patterns (such as the argument of \do).</p><p>Whenever the pattern parameter is omitted completely, the \d commands display all objects that are visible in the current schema search path – this is equivalent to using the pattern *. To see all objects in the database, use the pattern *.*.</p><h3 id="ClientUtilityReference-AdvancedFeatures">Advanced Features</h3><h4 id="ClientUtilityReference-Variables">Variables</h4><p>psql provides variable substitution features similar to common UNIX command shells. Variables are simply name/value pairs, where the value can be any string of any length. To set variables, use the psql meta-command \set:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="theme: Confluence; brush: java; gutter: false" style="font-size:12px;">testdb=> \set foo bar</pre>
</div></div><p>sets the variable foo to the value bar. To retrieve the content of the variable, precede the name with a colon and use it as the argument of any slash command:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="theme: Confluence; brush: java; gutter: false" style="font-size:12px;">testdb=> \echo :foo
bar</pre>
</div></div><p><strong>Note</strong>: The arguments of \set are subject to the same substitution rules as with other commands. Thus, you can construct interesting references such as \set :foo 'something' and get ‘soft links’ or ‘variable variables’ of Perl or PHP fame, respectively. Unfortunately, there is no way to do anything useful with these constructs. On the other hand, \set bar :foo is a perfectly valid way to copy a variable.</p><p>If you call \set without a second argument, the variable is set, with an empty string as a value. To unset (or delete) a variable, use the command \unset.</p><p>psql’s internal variable names can consist of letters, numbers, and underscores in any order and of any number. A number of these variables are treated specially by psql. They indicate certain option settings that can be changed at run time by altering the value of the variable or represent some state of the application. Although you can use these variables for any other purpose, this is not recommended, as the program might behave unexpectedly. By convention, all specially treated variables consist of all upper-case letters (and possibly numbers and underscores). To ensure maximum compatibility in the future, avoid using such variable names for your own purposes. A list of all specially treated variables are as follows:</p><p><span style="color: rgb(0,51,102);">AUTOCOMMIT</span></p><p style="margin-left: 30.0px;">When on (the default), each SQL command is automatically committed upon successful completion. To postpone commit in this mode, you must enter a BEGIN or START TRANSACTION SQL command. When off or unset, SQL commands are not committed until you explicitly issue COMMIT or END. The autocommit-on mode works by issuing an implicit BEGIN for you, just before any command that is not already in a transaction block and is not itself a BEGIN or other transaction-control command, nor a command that cannot be executed inside a transaction block (such as VACUUM).</p><p style="margin-left: 30.0px;">In autocommit-off mode, you must explicitly abandon any failed transaction by entering ABORT or ROLLBACK. Also keep in mind that if you exit the session without committing, your work will be lost.</p><p style="margin-left: 30.0px;">The autocommit-on mode is PostgreSQL’s traditional behavior, but autocommit-off is closer to the SQL spec. If you prefer autocommit-off, you may wish to set it in your ~/.psqlrc file.</p><p><span style="color: rgb(0,51,102);">DBNAME</span></p><p style="margin-left: 30.0px;">The name of the database you are currently connected to. This is set every time you connect to a database (including program start-up), but can be unset.</p><p><span style="color: rgb(0,51,102);">ECHO</span></p><p style="margin-left: 30.0px;">If set to all, all lines entered from the keyboard or from a script are written to the standard output before they are parsed or executed. To select this behavior on program start-up, use the switch -a. If set to queries, psql merely prints all queries as they are sent to the server. The switch for this is -e.</p><p><span style="color: rgb(0,51,102);">ECHO_HIDDEN</span></p><p style="margin-left: 30.0px;">When this variable is set and a backslash command queries the database, the query is first shown. This way you can study the HAWQ internals and provide similar functionality in your own programs. (To select this behavior on program start-up, use the switch -E.) If you set the variable to the value noexec, the queries are just shown but are not actually sent to the server and executed.</p><p><span style="color: rgb(0,51,102);">ENCODING</span></p><p style="margin-left: 30.0px;">The current client character set encoding.</p><p><span style="color: rgb(0,51,102);">FETCH_COUNT</span></p><p style="margin-left: 30.0px;">If this variable is set to an integer value > 0, the results of SELECT queries are fetched and displayed in groups of that many rows, rather than the default behavior of collecting the entire result set before display. Therefore, only a limited amount of memory is used, regardless of the size of the result set. Settings of 100 to 1000 are commonly used when enabling this feature. Keep in mind that when using this feature, a query may fail after having already displayed some rows.</p><p style="margin-left: 30.0px;">Although you can use any output format with this feature, the default-aligned format tends to look bad because each group of FETCH_COUNT rows will be formatted separately, leading to varying column widths across the row groups. The other output formats work better.</p><p><span style="color: rgb(0,51,102);">HISTCONTROL</span></p><p style="margin-left: 30.0px;">If this variable is set to ignorespace, lines which begin with a space are not entered into the history list. If set to a value of ignoredups, lines matching the previous history line are not entered. A value of ignoreboth combines the two options. If unset, or if set to any other value than those above, all lines read in interactive mode are saved on the history list.</p><p><span style="color: rgb(0,51,102);">HISTFILE</span></p><p style="margin-left: 30.0px;">The file name that will be used to store the history list. The default value is ~/.psql_history. For example, putting </p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="theme: Confluence; brush: sql; gutter: false" style="font-size:12px;">\set HISTFILE ~/.psql_history- :DBNAME</pre>
</div></div><p style="margin-left: 30.0px;">in ~/.psqlrc will cause psql to maintain a separate history for each database.</p><p><span style="color: rgb(0,51,102);">HISTSIZE</span></p><p style="margin-left: 30.0px;">The number of commands to store in the command history. The default value is 500.</p><p><span style="color: rgb(0,51,102);">HOST</span></p><p style="margin-left: 30.0px;">The database server host you are currently connected to. This is set every time you connect to a database (including program start-up), but can be unset.</p><p><span style="color: rgb(0,51,102);">IGNOREEOF</span></p><p style="margin-left: 30.0px;">If unset, sending an EOF character (usually CTRL+D) to an interactive session of psql will terminate the application. If set to a numeric value, that number of EOF characters are ignored before the application terminates. If the variable is set but has no numeric value, the default is 10.</p><p><span style="color: rgb(0,51,102);">LASTOID</span></p><p style="margin-left: 30.0px;">The value of the last affected OID, as returned from an INSERT or lo_insert command. This variable is only guaranteed to be valid until after the result of the next SQL command has been displayed.</p><p><span style="color: rgb(0,51,102);">ON_ERROR_ROLLBACK</span></p><p style="margin-left: 30.0px;">When on, if a statement in a transaction block generates an error, the error is ignored and the transaction continues. When interactive, such errors are only ignored in interactive sessions, and not when reading script files. When off (the default), a statement in a transaction block that generates an error aborts the entire transaction.</p><p style="margin-left: 30.0px;">The on_error_rollback-on mode works by issuing an implicit SAVEPOINT for you, just before each command that is in a transaction block, and rolls back to the savepoint on error.</p><p><span style="color: rgb(0,51,102);">ON_ERROR_STOP</span></p><p style="margin-left: 30.0px;">By default, if non-interactive scripts encounter an error, such as a malformed SQL command or internal meta-command, processing continues. This has been the traditional behavior of psql but it is sometimes not desirable. If this variable is set, script processing will immediately terminate. If the script was called from another script, it will terminate in the same fashion. If the outermost script was not called from an interactive psql session, but rather using the -f option, psql will return error code 3, to distinguish this case from fatal error conditions (error code 1).</p><p><span style="color: rgb(0,51,102);">PORT</span></p><p style="margin-left: 30.0px;">The database server port to which you are currently connected. This is set every time you connect to a database (including program start-up), but can be unset.</p><p><span style="color: rgb(0,51,102);">PROMPT1</span><br/><span style="color: rgb(0,51,102);">PROMPT2</span><br/><span style="color: rgb(0,51,102);">PROMPT3</span></p><p align="LEFT" style="margin-left: 30.0px;">These specify what the prompts psql issues should look like.</p><p><span style="color: rgb(0,51,102);">QUIET</span></p><p style="margin-left: 30.0px;">This variable is equivalent to the command line option -q. It is not very useful in interactive mode.</p><p><span style="color: rgb(0,51,102);">SINGLELINE</span></p><p style="margin-left: 30.0px;">This variable is equivalent to the command line option -S.</p><p><span style="color: rgb(0,51,102);">SINGLESTEP</span></p><p style="margin-left: 30.0px;">This variable is equivalent to the command line option -s.</p><p><span style="color: rgb(0,51,102);">USER</span></p><p style="margin-left: 30.0px;">The database user you are currently connected as. This is set every time you connect to a database (including program start-up), but can be unset.</p><p>VERBOSITY</p><p style="margin-left: 30.0px;">This variable can be set to the values default, verbose, or terse to control the verbosity of error reports.</p><h3 id="ClientUtilityReference-SQLInterpolation">SQL Interpolation</h3><p>An additional useful feature of psql variables is that you can substitute (interpolate) them into regular SQL statements. The syntax for this is again to prepend the variable name with a colon (:).</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="theme: Confluence; brush: java; gutter: false" style="font-size:12px;">testdb=> \set foo 'my_table'
testdb=> SELECT * FROM :foo;</pre>
</div></div><p>Variables can even contain unbalanced quotes or backslash commands. You must make sure that it makes sense where you put it. Variable interpolation will not be performed into quoted SQL entities.</p><p align="LEFT">A popular application of this facility is to refer to the last inserted OID in subsequent statements to build a foreign key scenario. Another possible use of this mechanism is to copy the contents of a file into a table column. First load the file into a variable and then proceed as above.</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="theme: Confluence; brush: java; gutter: false" style="font-size:12px;">testdb=> \set content '''' `cat my_file.txt` ''''
testdb=> INSERT INTO my_table VALUES (:content);</pre>
</div></div><p>One problem with this approach is that <em>my_file.txt </em><span style="font-size: medium;"> </span>might contain single quotes. These need to be escaped so that they don’t cause a syntax error when the second line is processed. This could be done with the program sed:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="theme: Confluence; brush: java; gutter: false" style="font-size:12px;">testdb=> \set content '''' `sed -e "s/'/''/g" -e 's/\\/\\\\/g' <my_file.txt '''' </pre>
</div></div><p align="LEFT">Note the use of different shell quoting conventions so that neither the single quote marks, nor the backslashes, are special to the shell. Backslashes are still special to sed, however, so we need to double them.</p><p align="LEFT">Since colons can legally appear in SQL commands, the following rule applies: the character sequence ":name" is not changed unless "name" is the name of a variable that is currently set. In any case you can escape a colon with a backslash to protect it from substitution. (The colon syntax for variables is standard SQL for embedded query languages, such as ECPG. The colon syntax for array slices and type casts are HAWQ extensions, hence the conflict.)</p><h4 id="ClientUtilityReference-Prompting">Prompting</h4><p align="LEFT">The prompts psql issues can be customized to your preference. The three variables PROMPT1, PROMPT2, and PROMPT3 contain strings and special escape sequences that describe the appearance of the prompt. Prompt 1 is the normal prompt that is issued when psql requests a new command. Prompt 2 is issued when more input is expected during command input because the command was not terminated with a semicolon, or a quote was not closed. Prompt 3 is issued when you run an SQL COPY command and you are expected to type in the row values on the terminal.</p><p align="LEFT">The value of the selected prompt variable is printed literally, except where a percent sign (%) is encountered. Depending on the next character, certain other text is substituted instead. Defined substitutions are:</p><p>%M</p><p align="LEFT" style="margin-left: 30.0px;">The full host name (with domain name) of the database server, or [local] if the connection is over a UNIX domain socket, or [local:/dir/name], if the UNIX domain socket is not at the compiled in default location.</p><p>%m</p><p align="LEFT" style="margin-left: 30.0px;">The host name of the database server, truncated at the first dot, or [local] if the connection is over a UNIX domain socket.</p><p>%></p><p align="LEFT" style="margin-left: 30.0px;">The port number at which the database server is listening.</p><p>%n</p><p align="LEFT" style="margin-left: 30.0px;">The database session user name. (The expansion of this value might change during a database session as the result of the command SET SESSION AUTHORIZATION.)</p><p>%/</p><p align="LEFT" style="margin-left: 30.0px;">The name of the current database.</p><p>%~</p><p align="LEFT" style="margin-left: 30.0px;">Like %/, but the output is ~ (tilde) if the database is your default database.</p><p>%#</p><p align="LEFT" style="margin-left: 30.0px;">If the session user is a database superuser, then a <strong>#</strong><span style="font-size: small;"> </span>, otherwise a <strong>></strong><span style="font-size: small;"> </span>. (The expansion of this value might change during a database session as the result of the command SET SESSION AUTHORIZATION.)</p><p>%R</p><p align="LEFT" style="margin-left: 30.0px;">In prompt 1, normally <strong>=</strong><span style="font-size: small;"> </span>, but <strong>^ </strong><span style="font-size: small;"> </span>if in single-line mode, and <strong>! </strong><span style="font-size: small;"> </span>if the session is disconnected from the database (which can happen if \connect fails). In prompt 2, the sequence is replaced by <strong>-</strong><span style="font-size: small;"> </span>, <strong>*</strong><span style="font-size: small;"> </span>, a single quote, a double quote, or a dollar sign, depending on whether psql expects more input because the command wasn’t terminated, because you are inside a /* ... */ comment, or because you are inside a quoted or dollar-escaped string. In prompt 3, the sequence doesn’t produce anything.</p><p>%x</p><p align="LEFT" style="margin-left: 30.0px;">Transaction status: an empty string when not in a transaction block, or <strong>* </strong><span style="font-size: small;"> </span>when in a transaction block, or<span style="font-size: small;"> </span>when in a failed transaction block, or <strong>? </strong><span style="font-size: small;"> </span>when the transaction state is indeterminate (for example, because there is no connection).</p><p>% <em>digits</em></p><p align="LEFT" style="margin-left: 30.0px;">The character with the indicated octal code is substituted.</p><p>%: <em>name</em><span style="font-size: medium;"> </span>:</p><p align="LEFT" style="margin-left: 30.0px;">The value of the psql variable name.</p><p>%` <em>command</em><span style="font-size: medium;"> </span>`</p><p align="LEFT" style="margin-left: 30.0px;">The output of command, similar to ordinary back-tick substitution.</p><p>%[ ... %]</p><p align="LEFT" style="margin-left: 30.0px;">Prompts may contain terminal control characters that, for example, change the color, background, or style of the prompt text, or change the title of the terminal window. In order for line editing to work properly, these non-printing control characters must be designated as invisible by surrounding them with %[ and %]. Multiple pairs of these may occur within the prompt. For example,</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="theme: Confluence; brush: java; gutter: false" style="font-size:12px;"> testdb=> \set PROMPT1 '%[%033[1;33;40m%]%n@%/%R%[%033[0m%]%#'</pre>
</div></div><p align="LEFT" style="margin-left: 30.0px;">results in a boldfaced (1;) yellow-on-black (33;40) prompt on VT100-compatible, color-capable terminals. To insert a percent sign into your prompt, write %%. The default prompts are '%/%R%# ' for prompts 1 and 2, and '>> ' for prompt 3.</p><h4 id="ClientUtilityReference-Command-LineEditing">Command-Line Editing</h4><p align="LEFT">psql supports the NetBSD <em>libedit </em><span style="font-size: medium;"> </span>library for convenient line editing and retrieval. The command history is automatically saved when psql exits and is reloaded when psql starts up. Tab-completion is also supported, although the completion logic makes no claim to be an SQL parser. If, for some reason, you do not like the tab completion, you can turn it off by putting this in a file named .inputrc in your home directory:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="theme: Confluence; brush: sql; gutter: false" style="font-size:12px;">$if psql
set disable-completion on
$endif</pre>
</div></div><h3 id="ClientUtilityReference-Environment">Environment</h3><p>PAGER</p><p align="LEFT" style="margin-left: 30.0px;">If the query results do not fit on the screen, they are piped through this command. Typical values are more or less. The default is platform-dependent. The use of the pager can be disabled by using the \pset command.</p><p>PGDATABASE<br/>PGHOST<br/>PGPORT<br/>PGUSER</p><p align="LEFT" style="margin-left: 30.0px;">Default connection parameters.</p><p>PSQL_EDITOR<br/>EDITOR<br/>VISUAL</p><p align="LEFT" style="margin-left: 30.0px;">Editor used by the \e command. The variables are examined in the order listed; the first that is set is used.</p><p>SHELL</p><p align="LEFT" style="margin-left: 30.0px;">Command executed by the \! command.</p><p>TMPDIR</p><p align="LEFT" style="margin-left: 30.0px;">Directory for storing temporary files. The default is /tmp.</p><p>Files</p><p align="LEFT">Before starting up, psql attempts to read and execute commands from the user’s ~/.psqlrc file.</p><p align="LEFT">The command-line history is stored in the file ~/.psql_history.</p><h3 id="ClientUtilityReference-Notes.3">Notes</h3><p align="LEFT">psql only works smoothly with servers of the same version. That does not mean other combinations will fail outright, but subtle and not-so-subtle problems might come up. Backslash commands are particularly likely to fail if the server is of a different version.</p><h3 id="ClientUtilityReference-NotesforWindowsusers">Notes for Windows users</h3><p align="LEFT">psql is built as a console application. Since the Windows console windows use a different encoding than the rest of the system, you must take special care when using 8-bit characters within psql. If psql detects a problematic console code page, it will warn you at startup. To change the console code page, two things are necessary:</p><p align="LEFT">Set the code page by entering cmd.exe /c chcp 1252. (1252 is a character encoding of the Latin alphabet, used by Microsoft Windows for English and some other Western languages.) If you are using Cygwin, you can put this command in /etc/profile.</p><p align="LEFT">Set the console font to Lucida Console, because the raster font does not work with the ANSI code page.</p><h3 id="ClientUtilityReference-Examples.7">Examples</h3><p align="LEFT">Start psql in interactive mode:<span style="font-size: medium;"><span style="font-size: medium;"> </span></span></p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="theme: Confluence; brush: sql; gutter: false" style="font-size:12px;">psql -p 54321 -U sally mydatabase</pre>
</div></div><p align="LEFT">In psql interactive mode, spread a command over several lines of input. Notice the changing prompt:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="theme: Confluence; brush: java; gutter: false" style="font-size:12px;">testdb=> CREATE TABLE my_table (
testdb(> first integer not null default 0,
testdb(> second text)
testdb-> ;
CREATE TABLE</pre>
</div></div><p align="LEFT">Look at the table definition:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="theme: Confluence; brush: java; gutter: false" style="font-size:12px;">testdb=> \d my_table
Table "my_table"
Attribute | Type | Modifier
-----------+---------+--------------------
first | integer | not null default 0
second | text |</pre>
</div></div><p align="LEFT">Run psql in non-interactive mode by passing in a file containing SQL commands:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="theme: Confluence; brush: java; gutter: false" style="font-size:12px;">psql -f /home/gpadmin/test/myscript.sql</pre>
</div></div><h2 id="ClientUtilityReference-vacuumdb">vacuumdb</h2><p>Garbage-collects and analyzes a database.</p><h3 id="ClientUtilityReference-Synopsis.9">Synopsis</h3><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="theme: Confluence; brush: sql; gutter: false" style="font-size:12px;">vacuumdb [connection-option...] [--full | -f] [-F] [--verbose | -v] [--analyze | -z] [--table | -t table [( column [,...] )] ][dbname]
vacuumdb [connection-options...] [--all | -a] [--full | -f] [-F][--verbose | -v] [--analyze | -z] vacuumdb --help | --version</pre>
</div></div><h3 id="ClientUtilityReference-Description.9">Description</h3><p>vacuumdb is a utility for cleaning a PostgreSQL database. vacuumdb will also generate internal statistics used by the PostgreSQL query optimizer. vacuumdb is a wrapper around the SQL command VACUUM. There is no effective difference between vacuuming databases via this utility and via other methods for accessing the server.</p><h3 id="ClientUtilityReference-Options.9">Options</h3><pre>-a | --all</pre><p style="margin-left: 30.0px;">Vacuums all databases.</p><pre>[-d] dbname <span> </span>| [--dbname] dbname</pre><p style="margin-left: 30.0px;">The name of the database to vacuum. If this is not specified and --all is not used, the database name is read from the environment variable PGDATABASE. If that is not set, the user name specified for the connection is used.</p><pre>-f | --full</pre><p style="margin-left: 30.0px;">Selects a full vacuum, which may reclaim more space, but takes much longer and exclusively locks the table.</p><p align="LEFT" style="margin-left: 30.0px;"><strong>Warning</strong>: A VACUUM FULL is not recommended in HAWQ.</p><pre>-F | --freeze</pre><p style="margin-left: 30.0px;">Freeze row transaction information.</p><pre>-q | --quiet</pre><p style="margin-left: 30.0px;">Do not display a response.</p><pre>-t <em>table </em><span style="font-size: medium;"> </span>[(<em>column</em><span style="font-size: medium;"> </span>)] | --table table <span style="font-size: medium;"> </span>[(<em>column</em><span style="font-size: medium;"> </span>)]</pre><p style="margin-left: 30.0px;">Clean or analyze this table only. Column names may be specified only in conjunction with the --analyze option. If you specify columns, you probably have to escape the parentheses from the shell.</p><pre>-v | --verbose</pre><p style="margin-left: 30.0px;">Print detailed information during processing.</p><pre>-z | --analyze</pre><p style="margin-left: 30.0px;">Collect statistics for use by the query planner.</p><h4 id="ClientUtilityReference-ConnectionOptions.9">Connection Options</h4><pre>-h host <span> </span>| --host host</pre><p style="margin-left: 30.0px;">The host name of the HAWQ master database server. If not specified, reads the name from the environment variable PGHOST or defaults to localhost.</p><pre>-p <em>port </em><span style="font-size: medium;"> </span>| --port port</pre><p style="margin-left: 30.0px;">The TCP port where the HAWQ master database server listens for connections. If not specified, reads the environment variable PGPORT, or defaults to 5432.</p><pre>-U <em>username </em><span style="font-size: medium;"> </span>| --username username</pre><p style="margin-left: 30.0px;">The database role name to connect as. If not specified, reads from the environment variable PGUSER or defaults to the current system role name.</p><pre>-w | --no-password</pre><p style="margin-left: 30.0px;">Use this to run automated batch jobs and scripts. In general, if the server requires password authentication ensure that it can be accessed through a .pgpass file. Otherwise the connection attempt will fail.</p><pre>-W | --password</pre><p style="margin-left: 30.0px;">Force a password prompt.</p><h3 id="ClientUtilityReference-Notes.4">Notes</h3><p>vacuumdb might need to connect several times to the master server, asking for a password each time. It is convenient to have a ~/.pgpass file in such cases.</p><h3 id="ClientUtilityReference-Examples.8">Examples</h3><p>To clean the database t<em>est</em><span style="font-size: medium;"> </span>:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="theme: Confluence; brush: sql; gutter: false" style="font-size:12px;">vacuumdb test</pre>
</div></div><p>To clean and analyze a database named <em>bigdb</em><span style="font-size: medium;"> </span>:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="theme: Confluence; brush: sql; gutter: false" style="font-size:12px;">vacuumdb --analyze bigdb</pre>
</div></div><p>To clean a single table <em>foo </em><span style="font-size: medium;"> </span>in a database named <em>mydb</em><span style="font-size: medium;"> </span>, and analyze a single column <em>bar </em>of the table. Note the quotes around the table and column names to escape the parentheses from the shell:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="theme: Confluence; brush: sql; gutter: false" style="font-size:12px;">vacuumdb --analyze --verbose --table 'foo(bar)' mydb</pre>
</div></div><h3 id="ClientUtilityReference-SeeAlso.8">See Also</h3><p>VACUUM, ANALYZE</p><p><span style="font-size: medium;"><span style="font-size: medium;"><span style="font-size: small;"> </span></span></span></p><p><span style="font-size: medium;"> </span></p><p> </p><p> </p><p align="LEFT"> </p><p> </p><p align="LEFT"> </p><p align="LEFT"> </p><p> </p><p align="LEFT"><span style="font-size: medium;"><span style="font-size: medium;"> </span></span></p><p> </p><p align="LEFT"><span style="font-size: medium;"><span style="font-size: medium;"> </span></span></p><p> </p><p align="LEFT"> </p><p> </p><p align="LEFT"> </p><p> </p><p align="LEFT"> </p><p> </p><p align="LEFT"> </p><p> </p><p> </p><p> </p><p align="LEFT"> </p><p> </p><p align="LEFT"> </p><p> </p><p align="LEFT"> </p><p><span style="font-size: medium;"><span style="font-size: medium;"><span style="font-size: medium;"> </span></span> </span></p><p><span style="font-size: medium;"><span style="font-size: medium;"><span style="font-size: medium;"><span style="font-size: medium;"> </span></span></span></span></p><p><span style="font-size: medium;"> </span></p><p> </p><p><span style="font-size: medium;"><span style="font-size: medium;"><span style="color: rgb(19,73,255);font-size: small;"> </span></span></span></p><p> </p><p> </p><p> </p>
</div></div>
</div><!-- end of content-->
</div><!-- end of container -->
</div><!--end of container-fluid-->
</div><!--end of main-wrap-->
<div class="site-footer desktop-only">
<div class="container-fluid">
<div class="site-footer-links">
<span class="version"><a href='/'>Pivotal Documentation</a></span>
<span>©
<script>
var d = new Date();
document.write(d.getFullYear());
</script>
<a href='http://gopivotal.com'>Pivotal Software</a> Inc. All Rights Reserved.
</span>
</div>
</div>
</div>
<script type="text/javascript">
(function() {
var didInit = false;
function initMunchkin() {
if(didInit === false) {
didInit = true;
Munchkin.init('625-IUJ-009');
}
}
var s = document.createElement('script');
s.type = 'text/javascript';
s.async = true;
s.src = document.location.protocol + '//munchkin.marketo.net/munchkin.js';
s.onreadystatechange = function() {
if (this.readyState == 'complete' || this.readyState == 'loaded') {
initMunchkin();
}
};
s.onload = initMunchkin;
document.getElementsByTagName('head')[0].appendChild(s);
})();
</script>
</div><!--end of viewport-->
<div id="scrim"></div>
</body>
</html>