Skip to content

Instantly share code, notes, and snippets.

Last active September 18, 2019 17:13
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
PostgreSQL bind parameters
# Usage: ruby parameter_bind.rb mylogfile.log
# Output: every sql command parsed with its parameters
sourceFileName = ARGV[0]
targetFile ="#{sourceFileName}.sql", 'w')
lines =, encoding: 'utf-8').scan(/(duration:.*)\sexecute.+:\s(.+)(\n.+parameters:(.+))?/)
lines.each do |line|
if line[2] != nil then
line[2].scan(/(\$\d+)\s=\s('.*?'|NULL)/).each do | param |
line[1].gsub!(Regexp.compile("#{Regexp.quote(param[0])}(?!\\d)"), param[1])
targetFile.puts "--#{line[0]}"
targetFile.puts "#{line[1]};"
targetFile.puts "\n"
ALTER SYSTEM SET log_min_duration_statement = 0;
ALTER SYSTEM SET log_filename = 'mylogfile';
ALTER SYSTEM SET log_truncate_on_rotation = ON;
SELECT pg_reload_conf();
SELECT pg_rotate_logfile();
--ALTER SYSTEM RESET log_min_duration_statement;
--ALTER SYSTEM RESET log_filename;
--ALTER SYSTEM RESET log_truncate_on_rotation;
--SELECT pg_reload_conf();
--SELECT pg_rotate_logfile();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment