postgresql-install.sh 45 KB

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