-
Notifications
You must be signed in to change notification settings - Fork 838
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
Question: is it possible to reduce dependencies for use as database/sql compatible driver? #822
Comments
The imports you mention are dependencies of the pgx module as a whole, but not of the core pgx package. i.e. They will not be included in your binary unless necessary. e.g. pgx includes adapters for several popular logging packages in the You can use |
Hi, you are right, all package imported inside subdirs are not included inside the final binary, however please try to build this sample program:
its size is 6018288 bytes, if you replace lib/pq with pgx this way:
the size is now 8809625 bytes. Do you think the size could be reduced somehow? Thank you |
I don't know of any ways to trim the core library down. I suspect it is mostly the extensive type support. Just as an experiment I removed the hstore type and array types from pgtype. The size of the final binary decreased by 700k. However, array support could not be separated into another package without breaking backwards compatibility. |
Thank you for your test. Just to give you an idea I report here the size cost for other SQL driver. In SFTPGo I can disable SQL drivers using build tags If I compile all the features using Go 1.15.1 on Linux with the following command:
the binary size is 26632144 bytes
|
Hi, what about adding a build tag? If someone wants to use pgx only as a This would be backward compatibile too, thank you |
It's might be possible, but I think the maintenance burden of wiring and testing this among the multiple packages that would need to be changed would be too high. |
Hi, I just tested pgx/v5, the binary size increase is now about 600k compared to lib/pq, much better! |
This is probably as much size reduction as we will get. I don't know of anything else that would be practical to trim off. |
pq recommend using pgx since pq itself is in maintenance mode. pgx offers support for things like client-side failover.
I believe we can close this issue now. Feel free to reopen it if you think it’s a mistake. |
This is not really fixed, pgx v5 increases the binary size in the same way as v4 if we add the I switched to pgx anyway because it is much better maintained and it has more features compared to |
Hi,
I'm evaluating to replace
lib/pq
withpgx
in SFTPGo usingpgx
as database/sql compatible driver. The conversion is quite simple I just need to replace the import and then usesql.Open("pgx",....
instead ofsql.Open("postgres",...
All my test cases pass, however my binary size increased of about 2MB. This is not a big deal however I'm wondering if it is possible to avoid uneeded imports and so reduce the binary size, for example in my
go.mod
I have now logrus, zap etc.. are all these deps required? If they are not required and you avoid to import them ingithub.com/jackc/pgx/v4/stdlib
they will not end up inside the final binary.To give you an idea:
lib/pg
, sftpgo size is 26632144 bytespgx
, sftpgo size is 28641456 bytesand here are the diffs for
go.mod
andgo.sum
:thank you
The text was updated successfully, but these errors were encountered: