postgresql-install.sh 44 KB

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