@@ -57,10 +57,7 @@ def query_csv(sql, config = configuration)
5757 def psql ( query , config = configuration )
5858 if ping ( config )
5959 if local?
60- execute ( psql_command ( config ) ,
61- :stdin => query ,
62- :hidden_patterns => [ config [ 'password' ] ] ,
63- :user => 'postgres' )
60+ execute ( "runuser - postgres -c '#{ psql_command ( config ) } ' -c '#{ query } '" )
6461 else
6562 execute ( psql_command ( config ) ,
6663 :stdin => query ,
@@ -73,9 +70,7 @@ def psql(query, config = configuration)
7370
7471 def ping ( config = configuration )
7572 if local?
76- execute? ( psql_command ( config ) + ' -c "SELECT 1 as ping"' ,
77- :hidden_patterns => [ config [ 'password' ] ] ,
78- :user => 'postgres' )
73+ execute? ( "runuser - postgres -c '#{ psql_command ( config ) } ' -c 'SELECT 1 as ping'" )
7974 else
8075 execute? ( psql_command ( config ) + ' -c "SELECT 1 as ping"' ,
8176 :hidden_patterns => [ config [ 'password' ] ] )
@@ -85,8 +80,7 @@ def ping(config = configuration)
8580 def dump_db ( file , config = configuration )
8681 if local?
8782 execute! ( "chown -R postgres:postgres #{ File . dirname ( file ) } " )
88- execute! ( dump_command ( config ) + " -f #{ file } " ,
89- :hidden_patterns => [ config [ 'password' ] ] , :user => 'postgres' )
83+ execute! ( "runuser - postgres -c '#{ dump_command ( config ) } -f #{ file } '" )
9084 else
9185 execute! ( dump_command ( config ) + " -f #{ file } " , :hidden_patterns => [ config [ 'password' ] ] )
9286 end
@@ -146,7 +140,7 @@ def db_version(config = configuration)
146140 # Note - t removes headers, -A removes alignment whitespace
147141 server_version_cmd = psql_command ( config ) + ' -c "SHOW server_version" -t -A'
148142 if local?
149- version_string = execute! ( server_version_cmd , :hidden_patterns => [ config [ 'password' ] ] , :user => 'postgres' )
143+ version_string = execute! ( "runuser - postgres -c ' #{ server_version_cmd } '" )
150144 else
151145 version_string = execute! ( server_version_cmd , :hidden_patterns => [ config [ 'password' ] ] )
152146 end
0 commit comments