3
0
Arne Teuke
2025-10-02 15:11:29 +02:00
parent 87d838f8be
commit ccdffca708
7 changed files with 57 additions and 0 deletions

View File

@@ -9,6 +9,7 @@
"csvlog",
"csvlogs",
"datestyle",
"datname",
"ecdh",
"fdatasync",
"geqo",
@@ -34,6 +35,7 @@
"multixact",
"naptime",
"nestloop",
"onlyif",
"partitionwise",
"pghba",
"pgsql",
@@ -47,6 +49,7 @@
"tablespaces",
"tidscan",
"timezonesets",
"trgm",
"usename",
"walsender",
"writethrough",

View File

@@ -19,6 +19,7 @@
# @param [String] pl_server_key the name of the server key
# @param [String] pl_ca_crt the name of the CA crt
# @param [Boolean] pl_manage_roles Whether to manage roles
# @param [Boolean] pl_manage_databases Whether to manage databases
# @summary Class contains all parameters for the postgresql_cd module.
##############################################################################
class postgresql_cd::params (
@@ -45,6 +46,7 @@ class postgresql_cd::params (
String $pl_server_key = 'server.key',
String $pl_ca_crt = 'root.crt',
Boolean $pl_manage_roles = true,
Boolean $pl_manage_databases = true,
) {
$fqdn = $facts['networking']['fqdn']

View File

@@ -0,0 +1,47 @@
## postgresql_cd::server::databases::db_df
# Module name: postgresql_cd
# Author: Arne Teuke (arne_teuke@confdroid.com.com)
# @summary define manages databases
# @see https://www.postgresql.org/docs/9.6/static/managing-databases.html
# @param [String] pl_db_name the name of the database to be created.
# @param [String] pl_owner_name the name of the owner for the database
# (optional), if none specified, the postgresql defaults will apply.
# @param [String] pl_db_action whether to create or drop the database.
# 'CREATE DATABASE' creates it, 'DROP DATABASE' drops it.
# @param [String] pl_db_extension
##############################################################################
define postgresql_cd::server::databases::db_df (
Optional[String] $pl_db_name = undef,
Optional[String] $pl_owner_name = undef,
Optional[String] $pl_db_action = undef,
String $pl_db_extension = 'pg_trgm',
) {
$pl_manage_databases = $postgresql_cd::params::pl_manage_databases
if $pl_manage_databases == true {
# create databases
if $pl_db_action == 'CREATE DATABASE' {
exec { "create_database_${name}":
command => template('postgresql_cd/server/databases/db_create_sql.erb'),
user => 'postgres',
path => ['/usr/bin','/bin'],
cwd => '/tmp',
unless => template('postgresql_cd/server/databases/unless_db_sql.erb'),
}
}
# Drop databases
if $pl_db_action == 'DROP DATABASE' {
exec { "drop_database_${name}":
command => template('postgresql_cd/server/databases/db_drop_sql.erb'),
user => 'postgres',
path => ['/usr/bin','/bin'],
cwd => '/tmp',
onlyif => template('postgresql_cd/server/databases/unless_drop_sql.erb'),
}
}
}
}

View File

@@ -0,0 +1,2 @@
psql -U postgres -tc "SELECT 1 FROM pg_database WHERE datname = '<%= @pl_db_name %>'" | grep -q 1 || psql -U postgres -c "CREATE DATABASE <%= @pl_db_name %> OWNER '<%= @pl_owner_name %>' "
psql -U postgres <%= @pl_db_name %> -c 'create extension if not exists <%= @pl_db_extension %>'

View File

@@ -0,0 +1 @@
dropdb -U postgres <%= @pl_db_name %> --if-exists

View File

@@ -0,0 +1 @@
psql -U postgres -c "SELECT datname FROM pg_database WHERE datname='<%= @pl_db_name %>' " | grep -q 1

View File

@@ -0,0 +1 @@
psql -U postgres -c "SELECT datname FROM pg_database WHERE datname='<%= @pl_db_name %>' " | grep -q 1