1 Puppet::Type.type(:postgresql_replication_slot).provide(:ruby) do
3 commands :psql => 'psql'
6 run_sql_command('SELECT * FROM pg_replication_slots;')[0].split("\n").select { |l| l =~ /\|/ }.map do |l|
7 name, *others = l.strip.split(/\s+\|\s+/)
15 def self.prefetch(resources)
17 if slot = resources[i.name]
24 @property_hash[:ensure] == :present
28 output = self.class.run_sql_command("SELECT * FROM pg_create_physical_replication_slot('#{resource[:name]}');")
30 @property_hash[:ensure] = :present
32 raise Puppet::Error, "Failed to create replication slot #{resource[:name]}:\n#{output[0]}"
37 output = self.class.run_sql_command("SELECT pg_drop_replication_slot('#{resource[:name]}');")
39 @property_hash[:ensure] = :absent
41 raise Puppet::Error, "Failed to destroy replication slot #{resource[:name]}:\n#{output[0]}"
47 def self.run_sql_command(sql)
48 command = ['psql', '-t', '-c', sql]
50 self.run_command(command, 'postgres', 'postgres')
53 def self.run_command(command, user, group)
54 if Puppet::PUPPETVERSION.to_f < 3.4
55 Puppet::Util::SUIDManager.run_and_capture(command, user, group)
57 output = Puppet::Util::Execution.execute(command, {
62 :override_locale => true,
63 :custom_environment => {}
65 [output, $CHILD_STATUS.dup]