-
Notifications
You must be signed in to change notification settings - Fork 252
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update postgresql to latest and enable it to run without root permissions #980
Conversation
Thanks for the pull request! Here is what will happen next:
Thank you for contributing! |
4984370
to
538edc7
Compare
cc: folks who have touched this plan recently: @themightychris @bodymindarts @eeyun for review |
postgresql/config/functions.sh
Outdated
@@ -59,13 +58,12 @@ master_ready() { | |||
bootstrap_replica_via_pg_basebackup() { | |||
echo 'Bootstrapping replica via pg_basebackup from leader ' | |||
|
|||
rm -rf {{pkg.svc_data_path}}/* | |||
pg_basebackup --pgdata={{pkg.svc_data_path}} --xlog-method=stream --dbname='postgres://{{cfg.replication.name}}@{{svc.leader.sys.ip}}:{{cfg.port}}/postgres' | |||
rm -rf {{cfg.data_directory}}/* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: we should put some kind of guard around this, in case {{cfg.data_directory}}
evaluates to "" and we blow away /
postgresql/default.toml
Outdated
@@ -15,4 +16,4 @@ name = 'replication' | |||
password = 'replication' | |||
lag_health_threshold = 1048576 | |||
enable = false | |||
archive_path = "{{pkg.svc_path}}/archive" | |||
archive_path = "hab/svc/postgresql/data/archive" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo here, I got it
update: reworked the data path stuff after feedback form @elliott-davis |
My only other concern here is what happens to your data on upgrade? |
super good point - this would totally break anyone who's upgrading their postgresql plan. argh! As an alternative, what if we keep the postgres data in |
@irvingpop I feel like you were on to the right solution about creating a pgdata dir in data but maybe just check to see if that directory exists and if not just create and move it in the init/reconfigure hook? |
pseudo-coding out a couple options here for the
if [[ -f "{{pkg.svc_data_path}}/PG_VERSION" ]]; then
echo "PGDATA detected in the root of the data path ( {{pkg.svc_data_path}} ), relocating...."
mkdir -p {{pkg.svc_data_path}}/pgdata
# bash extended globbing can cleanly move everything under a subfolder http://www.linuxjournal.com/content/bash-extended-globbing
mv {{pkg.svc_data_path}}/!(pgdata) {{pkg.svc_data_path}}/pgdata/
else
mkdir -p {{pkg.svc_data_path}}/pgdata
fi
if [[ -f "{{pkg.svc_data_path}}/PG_VERSION" ]]; then
echo "PGDATA detected in the root of the data path ( {{pkg.svc_data_path}} ), please manually move it to {{pkg.svc_data_path}}/pgdata before attempting to start the service"
exit 1
fi |
lingering question: does the init hook have any assurances that a hab supervised service isn't running? Update: yes, it does. we can safely relocate the data |
okay @elliott-davis @fnichol the latest commit should make life easier for existing installations that are upgrading. In testing:
|
a806e42
to
3d56e49
Compare
postgresql/config/functions.sh
Outdated
@@ -59,13 +63,14 @@ master_ready() { | |||
bootstrap_replica_via_pg_basebackup() { | |||
echo 'Bootstrapping replica via pg_basebackup from leader ' | |||
|
|||
rm -rf {{pkg.svc_data_path}}/* | |||
pg_basebackup --pgdata={{pkg.svc_data_path}} --xlog-method=stream --dbname='postgres://{{cfg.replication.name}}@{{svc.leader.sys.ip}}:{{cfg.port}}/postgres' | |||
# TODO: guard this rm -rf |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What kind of guard are you imagining? If there isn't a blocker, let's add it now. This rm -rf
rightfully makes us nervous but it is a necessary evil with pg_basebackup.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, that TODO comment is probably safe to delete now that it isn't simply rm -rf {{pkg.svc_data_path}}/*
.
I was thinking of this issue 🤦♀️ and I think the correct way to guard that is suggested by ShellCheck: https://github.com/koalaman/shellcheck/wiki/SC2115
Regardless this seems safer to me as-is now that there's the /pgdata
part in the argument. even in the highly unlikely situation that Habitat goes crazy and {{pkg.svc_data_path}}
evaluates to an empty string
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tl;dr - removed that comment
Okay, I'll get on trying this out--looking really good! |
postgresql/README.md
Outdated
@@ -12,7 +12,7 @@ hab start core/postgresql | |||
``` | |||
or | |||
``` | |||
docker run starkandwayne/postgresql | |||
docker run chefdemo/postgresql |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What would the origin be here after merge?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, I just realized that something (bldr?) is publishing official versions of this plan to https://hub.docker.com/r/habitat/postgresql/ so that would make more sense here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed!
24dce3c
to
9a74a47
Compare
postgresql/config/functions.sh
Outdated
rm -rf {{pkg.svc_data_path}}/* | ||
pg_basebackup --pgdata={{pkg.svc_data_path}} --xlog-method=stream --dbname='postgres://{{cfg.replication.name}}@{{svc.leader.sys.ip}}:{{cfg.port}}/postgres' | ||
rm -rf {{pkg.svc_data_path}}/pgdata/* | ||
pg_basebackup --pgdata={{pkg.svc_data_path}}/pgdata --xlog-method=stream --dbname='postgres://{{cfg.replication.name}}@{{svc.leader.sys.ip}}:{{cfg.port}}/postgres' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not blocking: a basebackup can take a long time for real-world databases. -v -P
will give you some more output that can be reassuring when you are on minute 5-6 (or 20-21) of bootstrapping :D.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great idea! done
Will this fix #887 ? |
@rsertelon not directly because this is for the |
222aa89
to
1ab3be7
Compare
…root Signed-off-by: Irving Popovetsky <[email protected]>
1ab3be7
to
dcdf884
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a couple of comments, but nothing show stopping. We're close to get this merged now, testing in a couple of hours. So sorry this took so long.
} | ||
|
||
ensure_dir_ownership() { | ||
echo 'Making sure hab user owns var, config and data paths' | ||
echo 'Making sure hab user owns var and data paths' | ||
chown -RL hab:hab {{pkg.svc_var_path}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should be able to get rid of this one now
chown -RL hab:hab {{pkg.svc_var_path}} | ||
chown -RL hab:hab {{pkg.svc_config_path}} | ||
chown -RL hab:hab {{pkg.svc_data_path}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
@@ -17,7 +17,7 @@ datestyle = 'iso, mdy' | |||
|
|||
default_text_search_config = 'pg_catalog.english' | |||
|
|||
data_directory = '{{pkg.svc_data_path}}' | |||
data_directory = '{{pkg.svc_data_path}}/pgdata' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While this will work, if anyone automatically updates their core/postgresql*
package, the data dir will have moved. Something we'll want to think on, but despite that, I like this change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nevermind, I missed the init
hook fix
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As we'll be testing and can resolve any issues, let's merge!
This PR updates postgresql and postgis to the latest (9.6.6 and 2.4.2 respectively) and also enables it to run without root permissions. In order to accomplish that I had to:
svc_data_path
to include thepgdata
andarchive
subfolders