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