Skip to content

Set correct permissions on the specified log directory #4226

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

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

cbandy
Copy link
Member

@cbandy cbandy commented Jul 30, 2025

Checklist:

  • Have you added an explanation of what your changes do and why you'd like them to be included?
  • Have you updated or added documentation for the change, as applicable?
  • Have you tested your changes on all related environments with successful results, as applicable?
    • Have you added automated tests?

Type of Changes:

  • Bug fix

What is the current behavior (link to any open issues here)?

Controllers ignore the specified "log_directory" when preparing directories for Postgres. This parameter can be specified when the OpenTelemetryLogs gate is disabled.

What is the new behavior (if this is a feature change)?

Controllers create the logs directory before starting Postgres.

Other Information:

Issue: PGO-2558

Copy link
Contributor

@benjaminjb benjaminjb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So when this is merged we

  • always run the func to set collector params (but we don't set anything if collector is not on)
  • create/set perms on the log dir depending on the log dir setting (which may be a relative path, e.g., when default is used)
  • handle relative paths in our path func

return fmt.Sprintf("%s/logs/postgres", dataMountPath)
// DataStorage returns the absolute path to the disk where cluster stores its data.
// Use [DataDirectory] for the exact directory that Postgres uses.
func DataStorage(cluster *v1beta1.PostgresCluster) string {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why pass in the cluster?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. 😬 Future-proofing, I guess. Something about being a constant does sit right with me, but it absolutely is a constant.

If I remove the arguments, should I also remove the function? Export the constant?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 I think I want things outside this package to not treat it as a constant, even though it is constant right now. Does that English make sense?

cbandy added 2 commits July 31, 2025 17:22
This function needed defined behavior for relative paths. For example,
the default log directory for Postgres is just "log" which it interprets
relative to the data directory.

Issue: PGO-2558
Controllers ignored the specified "log_directory" when preparing
directories for Postgres. This parameter can be specified when the
OpenTelemetryLogs gate is disabled.

This does not change what happens when the OpenTelemetryLogs gate is
enabled. In that case, controllers override the spec with their own
value and prepare that directory.

Issue: PGO-2558
Comment on lines 452 to 454
`(` + shell.MakeDirectories(DataDirectory(cluster), logDir) + `) ||`,
// FIXME: This error prints the wrong directory when logDir is relative (the default).
`halt "$(permissions ` + logDir + ` ||:)"`,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The challenge here is that initdb is only happy populating an empty data directory.

It is happy with this:

drwxrwxr-x. 2 postgres postgres Jul 31 17:04 pgdata/pg16

It is not happy with this:

drwxrwxr-x. 3 postgres postgres Jul 31 17:04 pgdata/pg16
drwxrwxr-x. 2 postgres postgres Jul 31 17:04 pgdata/pg16/log

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is now a time to pull the thread on moving logs out of pgdata completely?

@cbandy cbandy force-pushed the postgres-log-directory branch from d1ef339 to 5756ad3 Compare August 1, 2025 15:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants