These instructions are for adding new Census releases to D3's Census API that powers SDC and HIP. These instructions assume that you have four database dump files from Amanda like file_name.dump one for each year and release (1-year and 5-year) to be added.
- Visit https://censusreporter.tumblr.com/post/73727555158/easier-access-to-acs-data and find the link to the latest
TIGER Geodata. Save that link for future use in thewgetcommand below. - Log in to D3's Census API Server
>>> sftp username@165.227.87.138
>>> cd /home/sdcapi/census-api/data
>>> wget "https://census-extracts.b-cdn.net/tigerYEAR_backup.sql.gz" <-- Example link
>>> zcat tigerYEAR_backup.sql.gz | psql -q -U census censusSFTP dump files to D3's Census API Server
>>> sftp username@165.227.87.138
>>> cd /home/sdcapi/census-api/data
>>> put file_name1.dump
>>> put file_name2.dump
>>> put file_name3.dump
>>> put file_name4.dump- Log in to D3's Census API Server
>>> ssh username@165.227.87.138
>>> cd /home/sdcapi/census-api/data
>>> pg_restore --verbose -c --if-exists -d census -U postgres file_name1.dump
>>> pg_restore --verbose -c --if-exists -d census -U postgres file_name2.dump
>>> pg_restore --verbose -c --if-exists -d census -U postgres file_name3.dump
>>> pg_restore --verbose -c --if-exists -d census -U postgres file_name4.dumpMetadata tables also need to be updated for the new releases to be usable. Please follow the instructions for updating that repo and updating metadata tables here: https://github.com/NiJeLorg/census-table-metadata/blob/master/UPDATING_CENSUS_METADATA.md
- On your local machine, open
api.pyincensus_extractomatic. - In the array
allowed_acs, add the name of the newest acs release (ex.acs2019_5yr). Add the newest release at the top, but after thed3_presentrelease in the array. - In the array
allowed_tigeradd the name of the newest TIGER release (ex.tiger2019). Add the newest release at the top. - In the array
ACS_NAMESadd metadata of the newest ACS release (ex.'acs2019_5yr': {'name': 'ACS 2019 5-year', 'years': '2015-2019'},). Add the newest release at the top. - Once changed, push changes to github
>>> git commit -m 'message'
>>> git push origin masterThen pull in changes on the server:
>>> ssh username@165.227.87.138
>>> cd /home/sdcapi/census-api/
>>> git pull origin masterWhile still logged into the webserver, restart the webserver and cache services:
>>> service nginx restart
>>> service census-api restart
>>> service memcached restartWhen updating the 2019 ACS, the database user postgres was assigned ownership over all the imported tables and views. This was causing a 500 error for the API, since it uses the census database user to perfrom database queries. Running the following in psql solved the problem:
For views:
DO $$
DECLARE
cmd text;
BEGIN
FOR cmd in SELECT format('ALTER VIEW %I.%I.%I OWNER TO %I;', table_catalog, table_schema, table_name, 'census' ) FROM information_schema.views WHERE table_schema = 'acs2019_5yr'
LOOP
EXECUTE cmd;
END LOOP;
END;
$$;For tables:
DO $$
DECLARE
cmd text;
BEGIN
FOR cmd in SELECT format('ALTER TABLE %I.%I.%I OWNER TO %I;', table_catalog, table_schema, table_name, 'census') FROM information_schema.tables WHERE table_schema = 'acs2019_5yr'
LOOP
EXECUTE cmd;
END LOOP;
END;
$$;