postgresql-install.sh 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010
  1. #!/usr/bin/env bash
  2. YW=`echo "\033[33m"`
  3. RD=`echo "\033[01;31m"`
  4. BL=`echo "\033[36m"`
  5. GN=`echo "\033[1;92m"`
  6. CL=`echo "\033[m"`
  7. RETRY_NUM=10
  8. RETRY_EVERY=3
  9. NUM=$RETRY_NUM
  10. CM="${GN}✓${CL}"
  11. CROSS="${RD}✗${CL}"
  12. BFR="\\r\\033[K"
  13. HOLD="-"
  14. set -o errexit
  15. set -o errtrace
  16. set -o nounset
  17. set -o pipefail
  18. shopt -s expand_aliases
  19. alias die='EXIT=$? LINE=$LINENO error_exit'
  20. trap die ERR
  21. function error_exit() {
  22. trap - ERR
  23. local reason="Unknown failure occurred."
  24. local msg="${1:-$reason}"
  25. local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE"
  26. echo -e "$flag $msg" 1>&2
  27. exit $EXIT
  28. }
  29. function msg_info() {
  30. local msg="$1"
  31. echo -ne " ${HOLD} ${YW}${msg}..."
  32. }
  33. function msg_ok() {
  34. local msg="$1"
  35. echo -e "${BFR} ${CM} ${GN}${msg}${CL}"
  36. }
  37. function msg_error() {
  38. local msg="$1"
  39. echo -e "${BFR} ${CROSS} ${RD}${msg}${CL}"
  40. }
  41. msg_info "Setting up Container OS "
  42. sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen
  43. locale-gen >/dev/null
  44. while [ "$(hostname -I)" = "" ]; do
  45. 1>&2 echo -en "${CROSS}${RD} No Network! "
  46. sleep $RETRY_EVERY
  47. ((NUM--))
  48. if [ $NUM -eq 0 ]
  49. then
  50. 1>&2 echo -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}"
  51. exit 1
  52. fi
  53. done
  54. msg_ok "Set up Container OS"
  55. msg_ok "Network Connected: ${BL}$(hostname -I)"
  56. if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else msg_error "Internet NOT Connected"; exit 1; fi;
  57. RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs)
  58. if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi;
  59. msg_info "Updating Container OS"
  60. apt-get update &>/dev/null
  61. apt-get -y upgrade &>/dev/null
  62. msg_ok "Updated Container OS"
  63. msg_info "Installing Dependencies"
  64. apt-get install -y curl &>/dev/null
  65. apt-get install -y sudo &>/dev/null
  66. apt-get install -y gnupg2 &>/dev/null
  67. apt-get install -y lsb-release &>/dev/null
  68. msg_ok "Installed Dependencies"
  69. msg_info "Setting up PostgreSQL Repository"
  70. sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list' &>/dev/null
  71. wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add - &>/dev/null
  72. msg_ok "Setup PostgreSQL Repository"
  73. msg_info "Installing PostgreSQL"
  74. apt-get update &>/dev/null
  75. apt-get install -y postgresql-14 &>/dev/null
  76. cat <<EOF > /etc/postgresql/14/main/pg_hba.conf
  77. # PostgreSQL Client Authentication Configuration File
  78. # ===================================================
  79. #
  80. # Refer to the "Client Authentication" section in the PostgreSQL
  81. # documentation for a complete description of this file. A short
  82. # synopsis follows.
  83. #
  84. # This file controls: which hosts are allowed to connect, how clients
  85. # are authenticated, which PostgreSQL user names they can use, which
  86. # databases they can access. Records take one of these forms:
  87. #
  88. # local DATABASE USER METHOD [OPTIONS]
  89. # host DATABASE USER ADDRESS METHOD [OPTIONS]
  90. # hostssl DATABASE USER ADDRESS METHOD [OPTIONS]
  91. # hostnossl DATABASE USER ADDRESS METHOD [OPTIONS]
  92. # hostgssenc DATABASE USER ADDRESS METHOD [OPTIONS]
  93. # hostnogssenc DATABASE USER ADDRESS METHOD [OPTIONS]
  94. #
  95. # (The uppercase items must be replaced by actual values.)
  96. #
  97. # The first field is the connection type: "local" is a Unix-domain
  98. # socket, "host" is either a plain or SSL-encrypted TCP/IP socket,
  99. # "hostssl" is an SSL-encrypted TCP/IP socket, and "hostnossl" is a
  100. # non-SSL TCP/IP socket. Similarly, "hostgssenc" uses a
  101. # GSSAPI-encrypted TCP/IP socket, while "hostnogssenc" uses a
  102. # non-GSSAPI socket.
  103. #
  104. # DATABASE can be "all", "sameuser", "samerole", "replication", a
  105. # database name, or a comma-separated list thereof. The "all"
  106. # keyword does not match "replication". Access to replication
  107. # must be enabled in a separate record (see example below).
  108. #
  109. # USER can be "all", a user name, a group name prefixed with "+", or a
  110. # comma-separated list thereof. In both the DATABASE and USER fields
  111. # you can also write a file name prefixed with "@" to include names
  112. # from a separate file.
  113. #
  114. # ADDRESS specifies the set of hosts the record matches. It can be a
  115. # host name, or it is made up of an IP address and a CIDR mask that is
  116. # an integer (between 0 and 32 (IPv4) or 128 (IPv6) inclusive) that
  117. # specifies the number of significant bits in the mask. A host name
  118. # that starts with a dot (.) matches a suffix of the actual host name.
  119. # Alternatively, you can write an IP address and netmask in separate
  120. # columns to specify the set of hosts. Instead of a CIDR-address, you
  121. # can write "samehost" to match any of the server's own IP addresses,
  122. # or "samenet" to match any address in any subnet that the server is
  123. # directly connected to.
  124. #
  125. # METHOD can be "trust", "reject", "md5", "password", "scram-sha-256",
  126. # "gss", "sspi", "ident", "peer", "pam", "ldap", "radius" or "cert".
  127. # Note that "password" sends passwords in clear text; "md5" or
  128. # "scram-sha-256" are preferred since they send encrypted passwords.
  129. #
  130. # OPTIONS are a set of options for the authentication in the format
  131. # NAME=VALUE. The available options depend on the different
  132. # authentication methods -- refer to the "Client Authentication"
  133. # section in the documentation for a list of which options are
  134. # available for which authentication methods.
  135. #
  136. # Database and user names containing spaces, commas, quotes and other
  137. # special characters must be quoted. Quoting one of the keywords
  138. # "all", "sameuser", "samerole" or "replication" makes the name lose
  139. # its special character, and just match a database or username with
  140. # that name.
  141. #
  142. # This file is read on server startup and when the server receives a
  143. # SIGHUP signal. If you edit the file on a running system, you have to
  144. # SIGHUP the server for the changes to take effect, run "pg_ctl reload",
  145. # or execute "SELECT pg_reload_conf()".
  146. #
  147. # Put your actual configuration here
  148. # ----------------------------------
  149. #
  150. # If you want to allow non-local connections, you need to add more
  151. # "host" records. In that case you will also need to make PostgreSQL
  152. # listen on a non-local interface via the listen_addresses
  153. # configuration parameter, or via the -i or -h command line switches.
  154. # DO NOT DISABLE!
  155. # If you change this first entry you will need to make sure that the
  156. # database superuser can access the database using some other method.
  157. # Noninteractive access to all databases is required during automatic
  158. # maintenance (custom daily cronjobs, replication, and similar tasks).
  159. #
  160. # Database administrative login by Unix domain socket
  161. local all postgres trust
  162. # TYPE DATABASE USER ADDRESS METHOD
  163. # "local" is for Unix domain socket connections only
  164. local all all trust
  165. # IPv4 local connections:
  166. host all all 127.0.0.1/32 scram-sha-256
  167. host all all 0.0.0.0/24 md5
  168. # IPv6 local connections:
  169. host all all ::1/128 scram-sha-256
  170. host all all 0.0.0.0/0 md5
  171. EOF
  172. cat <<EOF > /etc/postgresql/14/main/postgresql.conf
  173. # -----------------------------
  174. # PostgreSQL configuration file
  175. # -----------------------------
  176. #
  177. # This file consists of lines of the form:
  178. #
  179. # name = value
  180. #
  181. # (The "=" is optional.) Whitespace may be used. Comments are introduced with
  182. # "#" anywhere on a line. The complete list of parameter names and allowed
  183. # values can be found in the PostgreSQL documentation.
  184. #
  185. # The commented-out settings shown in this file represent the default values.
  186. # Re-commenting a setting is NOT sufficient to revert it to the default value;
  187. # you need to reload the server.
  188. #
  189. # This file is read on server startup and when the server receives a SIGHUP
  190. # signal. If you edit the file on a running system, you have to SIGHUP the
  191. # server for the changes to take effect, run "pg_ctl reload", or execute
  192. # "SELECT pg_reload_conf()". Some parameters, which are marked below,
  193. # require a server shutdown and restart to take effect.
  194. #
  195. # Any parameter can also be given as a command-line option to the server, e.g.,
  196. # "postgres -c log_connections=on". Some parameters can be changed at run time
  197. # with the "SET" SQL command.
  198. #
  199. # Memory units: B = bytes Time units: us = microseconds
  200. # kB = kilobytes ms = milliseconds
  201. # MB = megabytes s = seconds
  202. # GB = gigabytes min = minutes
  203. # TB = terabytes h = hours
  204. # d = days
  205. #------------------------------------------------------------------------------
  206. # FILE LOCATIONS
  207. #------------------------------------------------------------------------------
  208. # The default values of these variables are driven from the -D command-line
  209. # option or PGDATA environment variable, represented here as ConfigDir.
  210. data_directory = '/var/lib/postgresql/14/main' # use data in another directory
  211. # (change requires restart)
  212. hba_file = '/etc/postgresql/14/main/pg_hba.conf' # host-based authentication file
  213. # (change requires restart)
  214. ident_file = '/etc/postgresql/14/main/pg_ident.conf' # ident configuration file
  215. # (change requires restart)
  216. # If external_pid_file is not explicitly set, no extra PID file is written.
  217. external_pid_file = '/var/run/postgresql/14-main.pid' # write an extra PID file
  218. # (change requires restart)
  219. #------------------------------------------------------------------------------
  220. # CONNECTIONS AND AUTHENTICATION
  221. #------------------------------------------------------------------------------
  222. # - Connection Settings -
  223. listen_addresses = '*' # what IP address(es) to listen on;
  224. # comma-separated list of addresses;
  225. # defaults to 'localhost'; use '*' for all
  226. # (change requires restart)
  227. port = 5432 # (change requires restart)
  228. max_connections = 100 # (change requires restart)
  229. #superuser_reserved_connections = 3 # (change requires restart)
  230. unix_socket_directories = '/var/run/postgresql' # comma-separated list of directories
  231. # (change requires restart)
  232. #unix_socket_group = '' # (change requires restart)
  233. #unix_socket_permissions = 0777 # begin with 0 to use octal notation
  234. # (change requires restart)
  235. #bonjour = off # advertise server via Bonjour
  236. # (change requires restart)
  237. #bonjour_name = '' # defaults to the computer name
  238. # (change requires restart)
  239. # - TCP settings -
  240. # see "man tcp" for details
  241. #tcp_keepalives_idle = 0 # TCP_KEEPIDLE, in seconds;
  242. # 0 selects the system default
  243. #tcp_keepalives_interval = 0 # TCP_KEEPINTVL, in seconds;
  244. # 0 selects the system default
  245. #tcp_keepalives_count = 0 # TCP_KEEPCNT;
  246. # 0 selects the system default
  247. #tcp_user_timeout = 0 # TCP_USER_TIMEOUT, in milliseconds;
  248. # 0 selects the system default
  249. # - Authentication -
  250. #authentication_timeout = 1min # 1s-600s
  251. #password_encryption = md5 # md5 or scram-sha-256
  252. #db_user_namespace = off
  253. # GSSAPI using Kerberos
  254. #krb_caseins_users = off
  255. # - SSL -
  256. #ssl = on
  257. #ssl_ca_file = ''
  258. #ssl_cert_file = '/etc/ssl/certs/ssl-cert-snakeoil.pem'
  259. #ssl_crl_file = ''
  260. #ssl_key_file = '/etc/ssl/private/ssl-cert-snakeoil.key'
  261. #ssl_ciphers = 'HIGH:MEDIUM:+3DES:!aNULL' # allowed SSL ciphers
  262. #ssl_prefer_server_ciphers = on
  263. #ssl_ecdh_curve = 'prime256v1'
  264. #ssl_min_protocol_version = 'TLSv1.2'
  265. #ssl_max_protocol_version = ''
  266. #ssl_dh_params_file = ''
  267. #ssl_passphrase_command = ''
  268. #ssl_passphrase_command_supports_reload = off
  269. #------------------------------------------------------------------------------
  270. # RESOURCE USAGE (except WAL)
  271. #------------------------------------------------------------------------------
  272. # - Memory -
  273. shared_buffers = 128MB # min 128kB
  274. # (change requires restart)
  275. #huge_pages = try # on, off, or try
  276. # (change requires restart)
  277. #temp_buffers = 8MB # min 800kB
  278. #max_prepared_transactions = 0 # zero disables the feature
  279. # (change requires restart)
  280. # Caution: it is not advisable to set max_prepared_transactions nonzero unless
  281. # you actively intend to use prepared transactions.
  282. #work_mem = 4MB # min 64kB
  283. #hash_mem_multiplier = 1.0 # 1-1000.0 multiplier on hash table work_mem
  284. #maintenance_work_mem = 64MB # min 1MB
  285. #autovacuum_work_mem = -1 # min 1MB, or -1 to use maintenance_work_mem
  286. #logical_decoding_work_mem = 64MB # min 64kB
  287. #max_stack_depth = 2MB # min 100kB
  288. #shared_memory_type = mmap # the default is the first option
  289. # supported by the operating system:
  290. # mmap
  291. # sysv
  292. # windows
  293. # (change requires restart)
  294. dynamic_shared_memory_type = posix # the default is the first option
  295. # supported by the operating system:
  296. # posix
  297. # sysv
  298. # windows
  299. # mmap
  300. # (change requires restart)
  301. # - Disk -
  302. #temp_file_limit = -1 # limits per-process temp file space
  303. # in kilobytes, or -1 for no limit
  304. # - Kernel Resources -
  305. #max_files_per_process = 1000 # min 64
  306. # (change requires restart)
  307. # - Cost-Based Vacuum Delay -
  308. #vacuum_cost_delay = 0 # 0-100 milliseconds (0 disables)
  309. #vacuum_cost_page_hit = 1 # 0-10000 credits
  310. #vacuum_cost_page_miss = 10 # 0-10000 credits
  311. #vacuum_cost_page_dirty = 20 # 0-10000 credits
  312. #vacuum_cost_limit = 200 # 1-10000 credits
  313. # - Background Writer -
  314. #bgwriter_delay = 200ms # 10-10000ms between rounds
  315. #bgwriter_lru_maxpages = 100 # max buffers written/round, 0 disables
  316. #bgwriter_lru_multiplier = 2.0 # 0-10.0 multiplier on buffers scanned/round
  317. #bgwriter_flush_after = 512kB # measured in pages, 0 disables
  318. # - Asynchronous Behavior -
  319. #effective_io_concurrency = 1 # 1-1000; 0 disables prefetching
  320. #maintenance_io_concurrency = 10 # 1-1000; 0 disables prefetching
  321. #max_worker_processes = 8 # (change requires restart)
  322. #max_parallel_maintenance_workers = 2 # taken from max_parallel_workers
  323. #max_parallel_workers_per_gather = 2 # taken from max_parallel_workers
  324. #parallel_leader_participation = on
  325. #max_parallel_workers = 8 # maximum number of max_worker_processes that
  326. # can be used in parallel operations
  327. #old_snapshot_threshold = -1 # 1min-60d; -1 disables; 0 is immediate
  328. # (change requires restart)
  329. #backend_flush_after = 0 # measured in pages, 0 disables
  330. #------------------------------------------------------------------------------
  331. # WRITE-AHEAD LOG
  332. #------------------------------------------------------------------------------
  333. # - Settings -
  334. #wal_level = replica # minimal, replica, or logical
  335. # (change requires restart)
  336. #fsync = on # flush data to disk for crash safety
  337. # (turning this off can cause
  338. # unrecoverable data corruption)
  339. #synchronous_commit = on # synchronization level;
  340. # off, local, remote_write, remote_apply, or on
  341. #wal_sync_method = fsync # the default is the first option
  342. # supported by the operating system:
  343. # open_datasync
  344. # fdatasync (default on Linux and FreeBSD)
  345. # fsync
  346. # fsync_writethrough
  347. # open_sync
  348. #full_page_writes = on # recover from partial page writes
  349. #wal_compression = off # enable compression of full-page writes
  350. #wal_log_hints = off # also do full page writes of non-critical updates
  351. # (change requires restart)
  352. #wal_init_zero = on # zero-fill new WAL files
  353. #wal_recycle = on # recycle WAL files
  354. #wal_buffers = -1 # min 32kB, -1 sets based on shared_buffers
  355. # (change requires restart)
  356. #wal_writer_delay = 200ms # 1-10000 milliseconds
  357. #wal_writer_flush_after = 1MB # measured in pages, 0 disables
  358. #wal_skip_threshold = 2MB
  359. #commit_delay = 0 # range 0-100000, in microseconds
  360. #commit_siblings = 5 # range 1-1000
  361. # - Checkpoints -
  362. #checkpoint_timeout = 5min # range 30s-1d
  363. max_wal_size = 1GB
  364. min_wal_size = 80MB
  365. #checkpoint_completion_target = 0.5 # checkpoint target duration, 0.0 - 1.0
  366. #checkpoint_flush_after = 256kB # measured in pages, 0 disables
  367. #checkpoint_warning = 30s # 0 disables
  368. # - Archiving -
  369. #archive_mode = off # enables archiving; off, on, or always
  370. # (change requires restart)
  371. #archive_command = '' # command to use to archive a logfile segment
  372. # placeholders: %p = path of file to archive
  373. # %f = file name only
  374. # e.g. 'test ! -f /mnt/server/archivedir/%f && cp %p /mnt/server/archivedir/%f'
  375. #archive_timeout = 0 # force a logfile segment switch after this
  376. # number of seconds; 0 disables
  377. # - Archive Recovery -
  378. # These are only used in recovery mode.
  379. #restore_command = '' # command to use to restore an archived logfile segment
  380. # placeholders: %p = path of file to restore
  381. # %f = file name only
  382. # e.g. 'cp /mnt/server/archivedir/%f %p'
  383. # (change requires restart)
  384. #archive_cleanup_command = '' # command to execute at every restartpoint
  385. #recovery_end_command = '' # command to execute at completion of recovery
  386. # - Recovery Target -
  387. # Set these only when performing a targeted recovery.
  388. #recovery_target = '' # 'immediate' to end recovery as soon as a
  389. # consistent state is reached
  390. # (change requires restart)
  391. #recovery_target_name = '' # the named restore point to which recovery will proceed
  392. # (change requires restart)
  393. #recovery_target_time = '' # the time stamp up to which recovery will proceed
  394. # (change requires restart)
  395. #recovery_target_xid = '' # the transaction ID up to which recovery will proceed
  396. # (change requires restart)
  397. #recovery_target_lsn = '' # the WAL LSN up to which recovery will proceed
  398. # (change requires restart)
  399. #recovery_target_inclusive = on # Specifies whether to stop:
  400. # just after the specified recovery target (on)
  401. # just before the recovery target (off)
  402. # (change requires restart)
  403. #recovery_target_timeline = 'latest' # 'current', 'latest', or timeline ID
  404. # (change requires restart)
  405. #recovery_target_action = 'pause' # 'pause', 'promote', 'shutdown'
  406. # (change requires restart)
  407. #------------------------------------------------------------------------------
  408. # REPLICATION
  409. #------------------------------------------------------------------------------
  410. # - Sending Servers -
  411. # Set these on the master and on any standby that will send replication data.
  412. #max_wal_senders = 10 # max number of walsender processes
  413. # (change requires restart)
  414. #wal_keep_size = 0 # in megabytes; 0 disables
  415. #max_slot_wal_keep_size = -1 # in megabytes; -1 disables
  416. #wal_sender_timeout = 60s # in milliseconds; 0 disables
  417. #max_replication_slots = 10 # max number of replication slots
  418. # (change requires restart)
  419. #track_commit_timestamp = off # collect timestamp of transaction commit
  420. # (change requires restart)
  421. # - Master Server -
  422. # These settings are ignored on a standby server.
  423. #synchronous_standby_names = '' # standby servers that provide sync rep
  424. # method to choose sync standbys, number of sync standbys,
  425. # and comma-separated list of application_name
  426. # from standby(s); '*' = all
  427. #vacuum_defer_cleanup_age = 0 # number of xacts by which cleanup is delayed
  428. # - Standby Servers -
  429. # These settings are ignored on a master server.
  430. #primary_conninfo = '' # connection string to sending server
  431. #primary_slot_name = '' # replication slot on sending server
  432. #promote_trigger_file = '' # file name whose presence ends recovery
  433. #hot_standby = on # "off" disallows queries during recovery
  434. # (change requires restart)
  435. #max_standby_archive_delay = 30s # max delay before canceling queries
  436. # when reading WAL from archive;
  437. # -1 allows indefinite delay
  438. #max_standby_streaming_delay = 30s # max delay before canceling queries
  439. # when reading streaming WAL;
  440. # -1 allows indefinite delay
  441. #wal_receiver_create_temp_slot = off # create temp slot if primary_slot_name
  442. # is not set
  443. #wal_receiver_status_interval = 10s # send replies at least this often
  444. # 0 disables
  445. #hot_standby_feedback = off # send info from standby to prevent
  446. # query conflicts
  447. #wal_receiver_timeout = 60s # time that receiver waits for
  448. # communication from master
  449. # in milliseconds; 0 disables
  450. #wal_retrieve_retry_interval = 5s # time to wait before retrying to
  451. # retrieve WAL after a failed attempt
  452. #recovery_min_apply_delay = 0 # minimum delay for applying changes during recovery
  453. # - Subscribers -
  454. # These settings are ignored on a publisher.
  455. #max_logical_replication_workers = 4 # taken from max_worker_processes
  456. # (change requires restart)
  457. #max_sync_workers_per_subscription = 2 # taken from max_logical_replication_workers
  458. #------------------------------------------------------------------------------
  459. # QUERY TUNING
  460. #------------------------------------------------------------------------------
  461. # - Planner Method Configuration -
  462. #enable_bitmapscan = on
  463. #enable_hashagg = on
  464. #enable_hashjoin = on
  465. #enable_indexscan = on
  466. #enable_indexonlyscan = on
  467. #enable_material = on
  468. #enable_mergejoin = on
  469. #enable_nestloop = on
  470. #enable_parallel_append = on
  471. #enable_seqscan = on
  472. #enable_sort = on
  473. #enable_incremental_sort = on
  474. #enable_tidscan = on
  475. #enable_partitionwise_join = off
  476. #enable_partitionwise_aggregate = off
  477. #enable_parallel_hash = on
  478. #enable_partition_pruning = on
  479. # - Planner Cost Constants -
  480. #seq_page_cost = 1.0 # measured on an arbitrary scale
  481. #random_page_cost = 4.0 # same scale as above
  482. #cpu_tuple_cost = 0.01 # same scale as above
  483. #cpu_index_tuple_cost = 0.005 # same scale as above
  484. #cpu_operator_cost = 0.0025 # same scale as above
  485. #parallel_tuple_cost = 0.1 # same scale as above
  486. #parallel_setup_cost = 1000.0 # same scale as above
  487. #jit_above_cost = 100000 # perform JIT compilation if available
  488. # and query more expensive than this;
  489. # -1 disables
  490. #jit_inline_above_cost = 500000 # inline small functions if query is
  491. # more expensive than this; -1 disables
  492. #jit_optimize_above_cost = 500000 # use expensive JIT optimizations if
  493. # query is more expensive than this;
  494. # -1 disables
  495. #min_parallel_table_scan_size = 8MB
  496. #min_parallel_index_scan_size = 512kB
  497. #effective_cache_size = 4GB
  498. # - Genetic Query Optimizer -
  499. #geqo = on
  500. #geqo_threshold = 12
  501. #geqo_effort = 5 # range 1-10
  502. #geqo_pool_size = 0 # selects default based on effort
  503. #geqo_generations = 0 # selects default based on effort
  504. #geqo_selection_bias = 2.0 # range 1.5-2.0
  505. #geqo_seed = 0.0 # range 0.0-1.0
  506. # - Other Planner Options -
  507. #default_statistics_target = 100 # range 1-10000
  508. #constraint_exclusion = partition # on, off, or partition
  509. #cursor_tuple_fraction = 0.1 # range 0.0-1.0
  510. #from_collapse_limit = 8
  511. #join_collapse_limit = 8 # 1 disables collapsing of explicit
  512. # JOIN clauses
  513. #force_parallel_mode = off
  514. #jit = on # allow JIT compilation
  515. #plan_cache_mode = auto # auto, force_generic_plan or
  516. # force_custom_plan
  517. #------------------------------------------------------------------------------
  518. # REPORTING AND LOGGING
  519. #------------------------------------------------------------------------------
  520. # - Where to Log -
  521. #log_destination = 'stderr' # Valid values are combinations of
  522. # stderr, csvlog, syslog, and eventlog,
  523. # depending on platform. csvlog
  524. # requires logging_collector to be on.
  525. # This is used when logging to stderr:
  526. #logging_collector = off # Enable capturing of stderr and csvlog
  527. # into log files. Required to be on for
  528. # csvlogs.
  529. # (change requires restart)
  530. # These are only used if logging_collector is on:
  531. #log_directory = 'log' # directory where log files are written,
  532. # can be absolute or relative to PGDATA
  533. #log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log' # log file name pattern,
  534. # can include strftime() escapes
  535. #log_file_mode = 0600 # creation mode for log files,
  536. # begin with 0 to use octal notation
  537. #log_truncate_on_rotation = off # If on, an existing log file with the
  538. # same name as the new log file will be
  539. # truncated rather than appended to.
  540. # But such truncation only occurs on
  541. # time-driven rotation, not on restarts
  542. # or size-driven rotation. Default is
  543. # off, meaning append to existing files
  544. # in all cases.
  545. #log_rotation_age = 1d # Automatic rotation of logfiles will
  546. # happen after that time. 0 disables.
  547. #log_rotation_size = 10MB # Automatic rotation of logfiles will
  548. # happen after that much log output.
  549. # 0 disables.
  550. # These are relevant when logging to syslog:
  551. #syslog_facility = 'LOCAL0'
  552. #syslog_ident = 'postgres'
  553. #syslog_sequence_numbers = on
  554. #syslog_split_messages = on
  555. # This is only relevant when logging to eventlog (win32):
  556. # (change requires restart)
  557. #event_source = 'PostgreSQL'
  558. # - When to Log -
  559. #log_min_messages = warning # values in order of decreasing detail:
  560. # debug5
  561. # debug4
  562. # debug3
  563. # debug2
  564. # debug1
  565. # info
  566. # notice
  567. # warning
  568. # error
  569. # log
  570. # fatal
  571. # panic
  572. #log_min_error_statement = error # values in order of decreasing detail:
  573. # debug5
  574. # debug4
  575. # debug3
  576. # debug2
  577. # debug1
  578. # info
  579. # notice
  580. # warning
  581. # error
  582. # log
  583. # fatal
  584. # panic (effectively off)
  585. #log_min_duration_statement = -1 # -1 is disabled, 0 logs all statements
  586. # and their durations, > 0 logs only
  587. # statements running at least this number
  588. # of milliseconds
  589. #log_min_duration_sample = -1 # -1 is disabled, 0 logs a sample of statements
  590. # and their durations, > 0 logs only a sample of
  591. # statements running at least this number
  592. # of milliseconds;
  593. # sample fraction is determined by log_statement_sample_rate
  594. #log_statement_sample_rate = 1.0 # fraction of logged statements exceeding
  595. # log_min_duration_sample to be logged;
  596. # 1.0 logs all such statements, 0.0 never logs
  597. #log_transaction_sample_rate = 0.0 # fraction of transactions whose statements
  598. # are logged regardless of their duration; 1.0 logs all
  599. # statements from all transactions, 0.0 never logs
  600. # - What to Log -
  601. #debug_print_parse = off
  602. #debug_print_rewritten = off
  603. #debug_print_plan = off
  604. #debug_pretty_print = on
  605. #log_checkpoints = off
  606. #log_connections = off
  607. #log_disconnections = off
  608. #log_duration = off
  609. #log_error_verbosity = default # terse, default, or verbose messages
  610. #log_hostname = off
  611. log_line_prefix = '%m [%p] %q%u@%d ' # special values:
  612. # %a = application name
  613. # %u = user name
  614. # %d = database name
  615. # %r = remote host and port
  616. # %h = remote host
  617. # %b = backend type
  618. # %p = process ID
  619. # %t = timestamp without milliseconds
  620. # %m = timestamp with milliseconds
  621. # %n = timestamp with milliseconds (as a Unix epoch)
  622. # %i = command tag
  623. # %e = SQL state
  624. # %c = session ID
  625. # %l = session line number
  626. # %s = session start timestamp
  627. # %v = virtual transaction ID
  628. # %x = transaction ID (0 if none)
  629. # %q = stop here in non-session
  630. # processes
  631. # %% = '%'
  632. # e.g. '<%u%%%d> '
  633. #log_lock_waits = off # log lock waits >= deadlock_timeout
  634. #log_parameter_max_length = -1 # when logging statements, limit logged
  635. # bind-parameter values to N bytes;
  636. # -1 means print in full, 0 disables
  637. #log_parameter_max_length_on_error = 0 # when logging an error, limit logged
  638. # bind-parameter values to N bytes;
  639. # -1 means print in full, 0 disables
  640. #log_statement = 'none' # none, ddl, mod, all
  641. #log_replication_commands = off
  642. #log_temp_files = -1 # log temporary files equal or larger
  643. # than the specified size in kilobytes;
  644. # -1 disables, 0 logs all temp files
  645. log_timezone = 'Etc/UTC'
  646. #------------------------------------------------------------------------------
  647. # PROCESS TITLE
  648. #------------------------------------------------------------------------------
  649. cluster_name = '14/main' # added to process titles if nonempty
  650. # (change requires restart)
  651. #update_process_title = on
  652. #------------------------------------------------------------------------------
  653. # STATISTICS
  654. #------------------------------------------------------------------------------
  655. # - Query and Index Statistics Collector -
  656. #track_activities = on
  657. #track_counts = on
  658. #track_io_timing = off
  659. #track_functions = none # none, pl, all
  660. #track_activity_query_size = 1024 # (change requires restart)
  661. stats_temp_directory = '/var/run/postgresql/14-main.pg_stat_tmp'
  662. # - Monitoring -
  663. #log_parser_stats = off
  664. #log_planner_stats = off
  665. #log_executor_stats = off
  666. #log_statement_stats = off
  667. #------------------------------------------------------------------------------
  668. # AUTOVACUUM
  669. #------------------------------------------------------------------------------
  670. #autovacuum = on # Enable autovacuum subprocess? 'on'
  671. # requires track_counts to also be on.
  672. #log_autovacuum_min_duration = -1 # -1 disables, 0 logs all actions and
  673. # their durations, > 0 logs only
  674. # actions running at least this number
  675. # of milliseconds.
  676. #autovacuum_max_workers = 3 # max number of autovacuum subprocesses
  677. # (change requires restart)
  678. #autovacuum_naptime = 1min # time between autovacuum runs
  679. #autovacuum_vacuum_threshold = 50 # min number of row updates before
  680. # vacuum
  681. #autovacuum_vacuum_insert_threshold = 1000 # min number of row inserts
  682. # before vacuum; -1 disables insert
  683. # vacuums
  684. #autovacuum_analyze_threshold = 50 # min number of row updates before
  685. # analyze
  686. #autovacuum_vacuum_scale_factor = 0.2 # fraction of table size before vacuum
  687. #autovacuum_vacuum_insert_scale_factor = 0.2 # fraction of inserts over table
  688. # size before insert vacuum
  689. #autovacuum_analyze_scale_factor = 0.1 # fraction of table size before analyze
  690. #autovacuum_freeze_max_age = 200000000 # maximum XID age before forced vacuum
  691. # (change requires restart)
  692. #autovacuum_multixact_freeze_max_age = 400000000 # maximum multixact age
  693. # before forced vacuum
  694. # (change requires restart)
  695. #autovacuum_vacuum_cost_delay = 2ms # default vacuum cost delay for
  696. # autovacuum, in milliseconds;
  697. # -1 means use vacuum_cost_delay
  698. #autovacuum_vacuum_cost_limit = -1 # default vacuum cost limit for
  699. # autovacuum, -1 means use
  700. # vacuum_cost_limit
  701. #------------------------------------------------------------------------------
  702. # CLIENT CONNECTION DEFAULTS
  703. #------------------------------------------------------------------------------
  704. # - Statement Behavior -
  705. #client_min_messages = notice # values in order of decreasing detail:
  706. # debug5
  707. # debug4
  708. # debug3
  709. # debug2
  710. # debug1
  711. # log
  712. # notice
  713. # warning
  714. # error
  715. #row_security = on
  716. #default_tablespace = '' # a tablespace name, '' uses the default
  717. #temp_tablespaces = '' # a list of tablespace names, '' uses
  718. # only default tablespace
  719. #default_table_access_method = 'heap'
  720. #check_function_bodies = on
  721. #default_transaction_isolation = 'read committed'
  722. #default_transaction_read_only = off
  723. #default_transaction_deferrable = off
  724. #session_replication_role = 'origin'
  725. #statement_timeout = 0 # in milliseconds, 0 is disabled
  726. #lock_timeout = 0 # in milliseconds, 0 is disabled
  727. #idle_in_transaction_session_timeout = 0 # in milliseconds, 0 is disabled
  728. #vacuum_freeze_min_age = 50000000
  729. #vacuum_freeze_table_age = 150000000
  730. #vacuum_multixact_freeze_min_age = 5000000
  731. #vacuum_multixact_freeze_table_age = 150000000
  732. #vacuum_cleanup_index_scale_factor = 0.1 # fraction of total number of tuples
  733. # before index cleanup, 0 always performs
  734. # index cleanup
  735. #bytea_output = 'hex' # hex, escape
  736. #xmlbinary = 'base64'
  737. #xmloption = 'content'
  738. #gin_fuzzy_search_limit = 0
  739. #gin_pending_list_limit = 4MB
  740. # - Locale and Formatting -
  741. datestyle = 'iso, mdy'
  742. #intervalstyle = 'postgres'
  743. timezone = 'Etc/UTC'
  744. #timezone_abbreviations = 'Default' # Select the set of available time zone
  745. # abbreviations. Currently, there are
  746. # Default
  747. # Australia (historical usage)
  748. # India
  749. # You can create your own file in
  750. # share/timezonesets/.
  751. #extra_float_digits = 1 # min -15, max 3; any value >0 actually
  752. # selects precise output mode
  753. #client_encoding = sql_ascii # actually, defaults to database
  754. # encoding
  755. # These settings are initialized by initdb, but they can be changed.
  756. lc_messages = 'C' # locale for system error message
  757. # strings
  758. lc_monetary = 'C' # locale for monetary formatting
  759. lc_numeric = 'C' # locale for number formatting
  760. lc_time = 'C' # locale for time formatting
  761. # default configuration for text search
  762. default_text_search_config = 'pg_catalog.english'
  763. # - Shared Library Preloading -
  764. #shared_preload_libraries = '' # (change requires restart)
  765. #local_preload_libraries = ''
  766. #session_preload_libraries = ''
  767. #jit_provider = 'llvmjit' # JIT library to use
  768. # - Other Defaults -
  769. #extension_destdir = '' # prepend path when loading extensions
  770. # and shared objects (added by Debian)
  771. #------------------------------------------------------------------------------
  772. # LOCK MANAGEMENT
  773. #------------------------------------------------------------------------------
  774. #deadlock_timeout = 1s
  775. #max_locks_per_transaction = 64 # min 10
  776. # (change requires restart)
  777. #max_pred_locks_per_transaction = 64 # min 10
  778. # (change requires restart)
  779. #max_pred_locks_per_relation = -2 # negative values mean
  780. # (max_pred_locks_per_transaction
  781. # / -max_pred_locks_per_relation) - 1
  782. #max_pred_locks_per_page = 2 # min 0
  783. #------------------------------------------------------------------------------
  784. # VERSION AND PLATFORM COMPATIBILITY
  785. #------------------------------------------------------------------------------
  786. # - Previous PostgreSQL Versions -
  787. #array_nulls = on
  788. #backslash_quote = safe_encoding # on, off, or safe_encoding
  789. #escape_string_warning = on
  790. #lo_compat_privileges = off
  791. #operator_precedence_warning = off
  792. #quote_all_identifiers = off
  793. #standard_conforming_strings = on
  794. #synchronize_seqscans = on
  795. # - Other Platforms and Clients -
  796. #transform_null_equals = off
  797. #------------------------------------------------------------------------------
  798. # ERROR HANDLING
  799. #------------------------------------------------------------------------------
  800. #exit_on_error = off # terminate session on any error?
  801. #restart_after_crash = on # reinitialize after backend crash?
  802. #data_sync_retry = off # retry or panic on failure to fsync
  803. # data?
  804. # (change requires restart)
  805. #------------------------------------------------------------------------------
  806. # CONFIG FILE INCLUDES
  807. #------------------------------------------------------------------------------
  808. # These options allow settings to be loaded from files other than the
  809. # default postgresql.conf. Note that these are directives, not variable
  810. # assignments, so they can usefully be given more than once.
  811. include_dir = 'conf.d' # include files ending in '.conf' from
  812. # a directory, e.g., 'conf.d'
  813. #include_if_exists = '...' # include file only if it exists
  814. #include = '...' # include file
  815. #------------------------------------------------------------------------------
  816. # CUSTOMIZED OPTIONS
  817. #------------------------------------------------------------------------------
  818. # Add settings for extensions here
  819. EOF
  820. sudo systemctl restart postgresql
  821. msg_ok "Installed PostgreSQL"
  822. read -r -p "Would you like to add Adminer? <y/N> " prompt
  823. if [[ $prompt == "y" || $prompt == "Y" || $prompt == "yes" || $prompt == "Yes" ]]
  824. then
  825. ADMINER="Y"
  826. else
  827. ADMINER="N"
  828. fi
  829. if [[ $ADMINER == "Y" ]]; then
  830. msg_info "Installing Adminer"
  831. sudo apt install adminer -y &>/dev/null
  832. sudo a2enconf adminer &>/dev/null
  833. sudo systemctl reload apache2 &>/dev/null
  834. msg_ok "Installed Adminer"
  835. fi
  836. PASS=$(grep -w "root" /etc/shadow | cut -b6);
  837. if [[ $PASS != $ ]]; then
  838. msg_info "Customizing Container"
  839. chmod -x /etc/update-motd.d/*
  840. touch ~/.hushlogin
  841. GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf"
  842. mkdir -p $(dirname $GETTY_OVERRIDE)
  843. cat << EOF > $GETTY_OVERRIDE
  844. [Service]
  845. ExecStart=
  846. ExecStart=-/sbin/agetty --autologin root --noclear --keep-baud tty%I 115200,38400,9600 \$TERM
  847. EOF
  848. systemctl daemon-reload
  849. systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//')
  850. msg_ok "Customized Container"
  851. fi
  852. msg_info "Cleaning up"
  853. apt-get autoremove >/dev/null
  854. apt-get autoclean >/dev/null
  855. msg_ok "Cleaned"