Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions cmd/api/handlers/v1/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func LoadConfig(rulesFile, docsFile string) error {
// @Param format query string false "Output format" Enums(json,alter_system,conf) default(json)
// @Param show_doc query string false "Show Documentation args" Enums(true,false) default(false)
// @Param include_pgbadger query string false "Add pgbadger configuration" Enums(true,false) default(false)
// @Param log_format query string false "Defines the log_format to be used" Enums(stderr,csvlog,syslog) default(stderr)
// @Param log_format query string false "Defines the log_format to be used (default: jsonlog for PG>=15, stderr otherwise)" Enums(stderr,csvlog,syslog,jsonlog)
// @Success 200 {object} ResponseHTTP{}
// @Router /v1/tuning/get-config [get]
func GetConfig(c *fiber.Ctx) error {
Expand Down Expand Up @@ -172,6 +172,12 @@ func parseConfigArgs(c *fiber.Ctx) (*configArgs, error) {
return nil, fmt.Errorf("could not parse total ram: %w", err)
}

// Set default log format based on PostgreSQL version
defaultLogFormat := "stderr"
if float32(pgVersion) >= 15.0 {
defaultLogFormat = "jsonlog"
}

return &configArgs{
pgVersion: float32(pgVersion),
totalRAM: parsedRAM,
Expand All @@ -184,7 +190,7 @@ func parseConfigArgs(c *fiber.Ctx) (*configArgs, error) {
outFormat: format.ExportFormat(c.Query("format", "json")),
showDoc: c.Query("show_doc", "false") == "true",
includePgbadger: c.Query("include_pgbadger", "false") == "true",
logFormat: c.Query("log_format", "stderr"),
logFormat: c.Query("log_format", defaultLogFormat),
}, nil
}

Expand Down
7 changes: 6 additions & 1 deletion cmd/pgconfigctl/cmd/tune.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ var tuneCmd = &cobra.Command{
Long: `Uses your server info to compute the PostgreSQL tuning aiming to give you a get-start to tune your server.`,
Run: func(cmd *cobra.Command, args []string) {

// Auto-select jsonlog for PostgreSQL 15+ if user didn't explicitly set log format
if !cmd.Flags().Changed("log-format") && pgVersion >= 15.0 {
logFormat = "jsonlog"
}

out, err := rules.Compute(
*input.NewInput(
osName,
Expand Down Expand Up @@ -101,7 +106,7 @@ func init() {
tuneCmd.PersistentFlags().MarkDeprecated("env-name", "please use --profile instead")
tuneCmd.PersistentFlags().IntVarP(&maxConnections, "max-connections", "M", 100, "Max expected connections")
tuneCmd.PersistentFlags().BoolVarP(&includePgbadger, "include-pgbadger", "B", false, "Include pgbadger params?")
tuneCmd.PersistentFlags().StringVarP(&logFormat, "log-format", "L", "csvlog", "Default log format")
tuneCmd.PersistentFlags().StringVarP(&logFormat, "log-format", "L", "csvlog", "Default log format (stderr, csvlog, syslog, jsonlog)")

tuneCmd.PersistentFlags().VarP(&totalRAM, "ram", "", "Total Memory in bytes")
tuneCmd.PersistentFlags().Lookup("ram").DefValue = totalRAM.String()
Expand Down
7 changes: 7 additions & 0 deletions pkg/category/log_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,12 @@ var (
{Format: "string", Name: "log_destination", Value: "csvlog"},
},
},
"jsonlog": {
Name: "jsonlog_config",
Description: "JSON Log Configuration",
Parameters: []ParamSliceOutput{
{Format: "string", Name: "log_destination", Value: "jsonlog"},
},
},
}
)