T i l
Postgres pg_rewind gotcha
I use pg_rewind for rewind a Postgres cluster which is ahead of the primary. Yesterday, after the rewind Postgres didn’t start. It failed with the below error. This is using 9.6 version pg_rewind client.
Sep 2 20:06:14.371503 productiondb[1]: [1-1] time=2022-09-02 20:06:14.338 GMT,pid=78197,user=admin,db=postgres,client=[local],appname=[unknown],vid=,xid=0 FATAL: the database system is starting up Sep 2 20:06:14.371611 productiondb[1]: [1-1] time=2022-09-02 20:06:14.370 GMT,pid=78184,user=,db=,client=,appname=,vid=,xid=0 LOG: entering standby mode Sep 2 20:06:14.371991 productiondb[1]: [1-1] time=2022-09-02 20:06:14.371 GMT,pid=78184,user=,db=,client=,appname=,vid=,xid=0 PANIC: could not open file "pg_replslot/ae0750b1/state": No such file or directory Sep 2 20:06:14.
T i l
functional options
I saw this pattern of a function taking optional parameters (variadic arguments) and I never understood why they do that until today.
There is a bit of a background on why I need to use functional pattern.
Let’s say I don’t use functional option. Then, all the arguments need to be passed. Also, difficult to set default values and implement logic for default values.
package main import ( "fmt" "log" ) type Config struct { Host string Port uint Visibility bool } type clientOption func(c *Config) error func newConfig(host string, opts .
T i l
Understanding pointers in Go
double pointers A pointer (whose value is another variable’s address) which points to another pointer
copying a pointer to another pointer copies the address
copying a de-referenced pointer to another de-referenced pointer updates the value of the one to another
https://gist.github.com/viggy28/604cda186ff1b872d562b31ca3976732
package main import "fmt" type DB struct { Name string } // double pointer // a pointer which points to another pointer func wrapperFunc(config **DB) func() error { return func() error { cfg := &DB{} (*cfg).
T i l
Misc notes on Go
go run command go run command is a quick way to run go program. However, what it does behind the screen is it compiles the program and runs an executable and removes it once the program is stopped.
byte is a built-in alias of uint8. rune is a built-in alias of int32.
The semicolon insertion rule In Go, I thought there is no need for semicolon at the end of the statement.
T i l
encoding miscellaneous
From the wiki,
In computing, data storage, and data transmission, character encoding is used to represent a repertoire of characters by some kind of encoding system that assigns a number to each character for digital representation. Okay, they mean converting character to some number for storing and transmitting data.
There are two popular character sets 1. ASCII 1. American Standard Code for Information Interchange 2. Pretty much all the characters and symbols in modern keyboard comes under ASCII 3.
T i l
Notes on makefile
There are two types of variable declaration.
recursively expanded variables - foo is assigned with bar which inturns assigned to ugh whose value is Huh? foo = $(bar) bar = $(ugh) ugh = Huh? all:;echo $(foo) $ make $ Huh? simply expanded variables - foo is assigned with bar however bar is not defined yet. so it outputs to nothing. foo := $(bar) bar := $(ugh) ugh := Huh?