I am trying to script the setup of PostGIS on my Amazon RDS Postgres instance. Here is the commands I am running:
create extension postgis;
create extension fuzzystrmatch;
create extension postgis_tiger_geocoder;
create extension postgis_topology;
CREATE FUNCTION exec(text) returns text language plpgsql volatile AS $f$ BEGIN EXECUTE $1; RETURN $1; END; $f$;
SELECT exec('ALTER TABLE ' || quote_ident(s.nspname) || '.' || quote_ident(s.relname) || ' OWNER TO rds_superuser')
FROM (
SELECT nspname, relname
FROM pg_class c JOIN pg_namespace n ON (c.relnamespace = n.oid)
WHERE nspname in ('tiger','topology') AND
relkind IN ('r','S','v') ORDER BY relkind = 'S')
s;
alter schema tiger owner to rds_superuser;
alter schema topology owner to rds_superuser;
When I log into the server with the psql client and run each command individually, everything works great.
Result of test:
dbname=> select na.address, na.streetname, na.streettypeabbrev, na.zip from normalize_address('1 Devonshire Place, Boston, MA 02109') as na;
address | streetname | streettypeabbrev | zip
---------+------------+------------------+-------
1 | Devonshire | Pl | 02109
(1 row)
When I drop all those commands into a .sql file and then try to run them all at once via a psql command...
PGPASSWORD='****' psql -h us-west-2-stg-db-1.***.rds.amazonaws.com -U dbuser -d dbname -f setup_postgis.sql -o setup_postgis.log
...I get the following error when trying to test the PostGIS functions:
dbname=> select na.address, na.streetname, na.streettypeabbrev, na.zip from normalize_address('1 Devonshire Place, Boston, MA 02109') as na;
ERROR: function normalize_address(unknown) does not exist
LINE 2: from normalize_address('1 Devonshire Place, Boston, MA 02109...
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
Any idea why this exact sequence of commands works when running command direct on server, but not when run via command line as a .sql file?
NOTE: I am certain the db user I am using to run the commands is in the rds_superuser role
show search_path
show for the server? Istiger
in there? – Mike Tpsql -f
it is not. How can I add a schema to the search path for that case? – Adam Duroshow search_path
; can be modified withalter database ...
DDL – Mike T