According to the pg_hba.conf snippet, a password is required if you connect from ::1, which is the IPv6 address for localhost.
It may be that the box on which you have the problem has the resolver configured so that the name "localhost" refers to both 127.0.0.1 (IPv4) and ::1 (IPv6), so that the command psql -h localhost...
may connect to one or the other address.
I'd suggest to check the /etc/hosts
file for different localhost entries, or bypass the resolver by connecting to 127.0.0.1, or update the pg_hba.conf with "trust" for IPv6 local connections.
Strictly speaking, there is no such thing as a "plpgsql script" - PL/pgSQL is the default procedural language of PostgreSQL. It's either an SQL script or a plpgsql function / procedure. Your example seems to indicate an SQL script.
You could create a (server-side ) plpgsql (or sql) function instead, that takes any number of arguments. It's very simple as long as the arguments are values
. It gets a bit more complicated if the arguments include identifiers. Then you'll have to use PL/pgSQL with dynamic SQL and EXECUTE
.
PL/pgSQL is pre-installed by default in PostgreSQL 9.0 or later. You have to install it once per database in Postgres 8.3, though:
CREATE LANGUGAGE plpgsql;
Speaking of the version: you should consider upgrading to a current version of PostgreSQL. v8.3 is very old by now, end-of-life in early 2013.
Since you seem to have a ready SQL script I'll demonstrate an SQL function. Simple dummy function with two integer arguments:
CREATE OR REPLACE FUNCTION func(int, int)
LANGUAGE sql RETURNS void AS
$func$
UPDATE tbl1 SET col1 = $1 WHERE id = $2;
UPDATE tbl2 SET col1 = $1 WHERE id = $2;
$func$;
You can find many more sophisticated examples for plpgsql here on dba.SE or on SO.
You can call this function and hand in parameters in a shell script:
Basic example for a call in a shell script that uses input parameters for integer parameters (no single-quotes around the value needed):
psql mydb -c "SELECT func($1, $2)"
Or with any data type:
psql mydb -c "SELECT func2('$1'::text, '$2'::numeric)"
-c
executes one command string and then exits.
More about command line arguments of psql in the manual.
Best Answer
Assuming your pager is
less
, tryLESS=-FX; export LESS
in your shell environment.From
man less
:To have this only in psql, set it with a meta-command in
.psqlrc
: