Skip to content

Instantly share code, notes, and snippets.

@tomredsky
Created March 4, 2019 15:59
Show Gist options
  • Save tomredsky/17ec96bc8771a17c1102a4821532d5f6 to your computer and use it in GitHub Desktop.
Save tomredsky/17ec96bc8771a17c1102a4821532d5f6 to your computer and use it in GitHub Desktop.
#!/bin/bash
PSQL="/usr/bin/psql"
PGUSER="dpaikkos"
DBNAME="import"
DUMP="sirius-latest.pg"
REMOTE="proxima"
rm -f $DUMP
/usr/bin/rsync -La --progress sirius:/data/pg_dumps/latest.pg ${DUMP}
$PSQL -d postgres -U $PGUSER<<EOF
SET statement_timeout = 0;
SET lock_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SET check_function_bodies = false;
SET client_min_messages = warning;
SET search_path = public, pg_catalog;
DROP DATABASE IF EXISTS ${DBNAME}_old;
ALTER DATABASE $DBNAME RENAME TO ${DBNAME}_old;
CREATE DATABASE $DBNAME WITH OWNER $PGUSER ENCODING='UTF8' LC_CTYPE='en_GB.UTF8' LC_COLLATE='en_GB.UTF8' TEMPLATE template0;
CREATE FUNCTION date2text(date) RETURNS character varying
LANGUAGE sql IMMUTABLE STRICT
AS $_$select $1::text$_$;
CREATE FUNCTION norm_key_val(text[], text[]) RETURNS text
LANGUAGE c IMMUTABLE
AS '/usr/lib/mfpgex.so', 'norm_key_val';
CREATE FUNCTION ml_secondary_fulltext_trigger_del() RETURNS trigger
LANGUAGE plpgsql
AS $$
BEGIN
UPDATE ml
SET fulltext = to_tsvector('pg_catalog.english', ml_fulltext_by_cod(ml.cod))
WHERE ml.cod = OLD.cod;
RETURN NULL;
END
$$;
GRANT Usage on LANGUAGE SQL to buildbot;
GRANT EXECUTE ON FUNCTION norm_key_val(text[], text[]) to buildbot;
GRANT EXECUTE ON FUNCTION date2text(date) to buildbot;
EOF
echo "Importing data"
$PSQL -d $DBNAME -U $PGUSER -f $DUMP
~
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment