Skip to content

Commit

Permalink
Merge pull request #563 from mattmundell/doc-release-switching
Browse files Browse the repository at this point in the history
Document switching between releases when using Postgres
  • Loading branch information
timopollmeier authored May 28, 2019
2 parents c10c0ad + 326004b commit 1a17b48
Showing 1 changed file with 24 additions and 85 deletions.
109 changes: 24 additions & 85 deletions doc/postgres-HOWTO
Original file line number Diff line number Diff line change
Expand Up @@ -57,91 +57,30 @@ Migrating from SQLite to PostgreSQL
3 Run "greenbone-certdata-sync".


Handy script to drop all data
-----------------------------

#!/bin/sh

export PGOPTIONS='--client-min-messages=warning'

PSQL="psql -q gvmd --pset pager=off -t -c"

$PSQL "`psql gvmd --pset pager=off -t -c \"select 'drop table '||schemaname||'.'||tablename||' CASCADE;' from pg_tables where schemaname = 'public' order by schemaname, tablename;\"`"

$PSQL "DROP FUNCTION IF EXISTS public.common_cve(text, text);";
$PSQL "DROP FUNCTION IF EXISTS public.create_index(text, text, text);";
$PSQL "DROP FUNCTION IF EXISTS public.create_index(text, text, text, text);";
$PSQL "DROP FUNCTION IF EXISTS public.current_severity(real, text);";
$PSQL "DROP FUNCTION IF EXISTS public.dynamic_severity();";
$PSQL "DROP FUNCTION IF EXISTS public.group_concat_pair(text, text, text);";
$PSQL "DROP FUNCTION IF EXISTS public.hosts_contains(text, text);";
$PSQL "DROP FUNCTION IF EXISTS public.iso_time(integer);";
$PSQL "DROP FUNCTION IF EXISTS public.level_max_severity(text, text);";
$PSQL "DROP FUNCTION IF EXISTS public.level_min_severity(text, text);";
$PSQL "DROP FUNCTION IF EXISTS public.lower(integer);";
$PSQL "DROP FUNCTION IF EXISTS public.m_now();";
$PSQL "DROP FUNCTION IF EXISTS public.make_uuid();";
$PSQL "DROP FUNCTION IF EXISTS public.max_hosts(text, text);";
$PSQL "DROP FUNCTION IF EXISTS public.next_time(integer, integer, integer);";
$PSQL "DROP FUNCTION IF EXISTS public.now();";
$PSQL "DROP FUNCTION IF EXISTS public.order_inet(text);";
$PSQL "DROP FUNCTION IF EXISTS public.order_message_type(text);";
$PSQL "DROP FUNCTION IF EXISTS public.order_port(text);";
$PSQL "DROP FUNCTION IF EXISTS public.order_role(text);";
$PSQL "DROP FUNCTION IF EXISTS public.order_threat(text);";
$PSQL "DROP FUNCTION IF EXISTS public.report_active(integer);";
$PSQL "DROP FUNCTION IF EXISTS public.report_host_count(integer);";
$PSQL "DROP FUNCTION IF EXISTS public.report_progress(integer);";
$PSQL "DROP FUNCTION IF EXISTS public.report_progress_active(integer);";
$PSQL "DROP FUNCTION IF EXISTS public.report_result_host_count(integer, integer);";
$PSQL "DROP FUNCTION IF EXISTS public.report_severity(integer, integer);";
$PSQL "DROP FUNCTION IF EXISTS public.report_severity(integer, integer, integer);";
$PSQL "DROP FUNCTION IF EXISTS public.report_severity_count(integer, integer, integer, text);";
$PSQL "DROP FUNCTION IF EXISTS public.report_severity_count(integer, integer, text);";
$PSQL "DROP FUNCTION IF EXISTS public.resource_name(text, text, integer);";
$PSQL "DROP FUNCTION IF EXISTS public.run_status_name(integer);";
$PSQL "DROP FUNCTION IF EXISTS public.severity_class();";
$PSQL "DROP FUNCTION IF EXISTS public.severity_in_level(double precision, text);";
$PSQL "DROP FUNCTION IF EXISTS public.severity_in_level(text, text);";
$PSQL "DROP FUNCTION IF EXISTS public.severity_matches(double precision, double precision);";
$PSQL "DROP FUNCTION IF EXISTS public.severity_matches_ov(double precision, double precision);";
$PSQL "DROP FUNCTION IF EXISTS public.severity_to_level(double precision, integer);";
$PSQL "DROP FUNCTION IF EXISTS public.severity_to_level(text, integer);";
$PSQL "DROP FUNCTION IF EXISTS public.severity_to_type(double precision);";
$PSQL "DROP FUNCTION IF EXISTS public.t();";
$PSQL "DROP FUNCTION IF EXISTS public.tag(text, text);";
$PSQL "DROP FUNCTION IF EXISTS public.task_last_report(integer);";
$PSQL "DROP FUNCTION IF EXISTS public.task_second_last_report(integer);";
$PSQL "DROP FUNCTION IF EXISTS public.task_severity(integer, integer);";
$PSQL "DROP FUNCTION IF EXISTS public.task_severity(integer, integer, integer);";
$PSQL "DROP FUNCTION IF EXISTS public.task_threat_level(integer, integer);";
$PSQL "DROP FUNCTION IF EXISTS public.task_threat_level(integer, integer, integer);";
$PSQL "DROP FUNCTION IF EXISTS public.task_trend(integer, integer);";
$PSQL "DROP FUNCTION IF EXISTS public.task_trend(integer, integer, integer);";
$PSQL "DROP FUNCTION IF EXISTS public.uniquify(text, text, integer, text);";
$PSQL "DROP FUNCTION IF EXISTS public.user_can_everything(text);";
$PSQL "DROP FUNCTION IF EXISTS public.user_has_super_on_resource(text, integer);";
$PSQL "DROP FUNCTION IF EXISTS public.user_owns(text, integer);";
$PSQL "DROP FUNCTION IF EXISTS public.valid_db_resource_type(text);";

$PSQL "DROP AGGREGATE IF EXISTS public.group_concat (text, text);";
$PSQL "DROP AGGREGATE IF EXISTS public.group_concat_pair (text, text, text);";

$PSQL "DROP INDEX IF EXISTS public.nvt_cves_by_oid;";
$PSQL "DROP INDEX IF EXISTS public.nvt_selectors_by_family_or_nvt;";
$PSQL "DROP INDEX IF EXISTS public.nvt_selectors_by_name;";
$PSQL "DROP INDEX IF EXISTS public.nvts_by_creation_time;";
$PSQL "DROP INDEX IF EXISTS public.nvts_by_family;";
$PSQL "DROP INDEX IF EXISTS public.nvts_by_name;";
$PSQL "DROP INDEX IF EXISTS public.report_host_details_by_report_host_and_name_and_value;";
$PSQL "DROP INDEX IF EXISTS public.report_hosts_by_report_and_host;";
$PSQL "DROP INDEX IF EXISTS public.results_by_report;";

echo -n "\\d+: "
$PSQL "\d+"

echo "\\df: "
$PSQL "\df"
Switching between releases
--------------------------

There are two factors for developers to consider when switching between
releases if they are using Postgres as the backend:

1 gvmd uses C server-side extensions that link to gvm-libs, so Postgres
needs to be able to find the version of gvm-libs that goes with gvmd.

One way to do this is to modify ld.so.conf and run ldconfig after
installing the desired gvmd version.

2 The Postgres database "gvmd" must be the version that is supported by
gvmd. If it is too high, gvmd will refuse to run. If it is too low
gvmd will only run if the database is migrated to the higher version.

One way to handle this is to switch between different versions of the
database using RENAME:

sudo -u postgres psql -q --command='ALTER DATABASE gvmd RENAME TO gvmd_10;'
sudo -u postgres psql -q --command='ALTER DATABASE gvmd_master RENAME TO gvmd;'

Note that for OpenVAS-9 the database name is "tasks", so this step is not
necessary.


Analyzing the size of the tables
Expand Down

0 comments on commit 1a17b48

Please sign in to comment.