Skip to content

Commit

Permalink
add_data: Add set_synchronous_commit() for speed
Browse files Browse the repository at this point in the history
See #77
  • Loading branch information
anthonyfok committed Jun 3, 2021
1 parent a5b5b8d commit f27678e
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions python/add_data.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,24 @@ DSRA_REPOSITORY=https://github.com/OpenDRR/scenario-catalogue/tree/master/FINISH
####################### Define helper functions #######################
############################################################################################

# set_synchronous_commit sets database's synchronous_commit
# to "off" for speed, or to "on" for reliability.
set_synchronous_commit() {
if [ "$#" -ne 1 ]; then
echo "ERROR: ${FUNCNAME[0]} requires exactly one argument, but $# was given."
exit 1
fi
local on_off="$1"

echo " - psql: Setting synchronous_commit TO $on_off..."
psql -h "$POSTGRES_HOST" -U "$POSTGRES_USER" -d "$DB_NAME" -a \
-c "SHOW synchronous_commit;"
psql -h "$POSTGRES_HOST" -U "$POSTGRES_USER" -d "$DB_NAME" -a \
-c "ALTER DATABASE $DB_NAME SET synchronous_commit TO $on_off;"
psql -h "$POSTGRES_HOST" -U "$POSTGRES_USER" -d "$DB_NAME" -a \
-c "SHOW synchronous_commit;"
}

# run_ogr2ogr creates boundaries schema geometry tables from default geopackages.
# (Change ogr2ogr PATH / geopackage path if necessary to run.)
run_ogr2ogr() {
Expand Down Expand Up @@ -247,6 +265,10 @@ git clone https://github.com/OpenDRR/model-factory.git --depth 1 || (cd model-fa
cp model-factory/scripts/*.* .
#rm -rf model-factory


# Speed up PostgreSQL operations
set_synchronous_commit off

############################################################################################
####################### Process Exposure and Ancillary Data #######################
############################################################################################
Expand Down Expand Up @@ -621,4 +643,8 @@ fi
echo -e "\n Loading Kibana Saved Objects"
curl -X POST -H "securitytenant: global" "${KIBANA_ENDPOINT}/api/saved_objects/_import" -H "kbn-xsrf: true" --form [email protected]


# Restore PostgreSQL synchronous_commit default setting (on) for reliability
set_synchronous_commit on

tail -f /dev/null & wait

0 comments on commit f27678e

Please sign in to comment.