Can I disable binlogs to save space temporarily I am using percona mysql 8.
I do not use any type of replication, but I read that binlogs are useful for data recovery. I would like to turn of binlogging and flush them while I run pt-online-schema-change to do non-impacting OPTIMIZE table.
After it is done, I want to turn binlogging back on (and then make efforts to move to a server with more space).
Is this safe and recommended? I need to optimize a table and can't go offline and making a copy of the table will make me run out of space unless I remove the 50GB of binlogs
What you need to do is set sql_log_bin to 0 as you start pt-online-schema-change using set-vars
pt-online-schema-change --set-vars sql_log_bin=0

Your binary logs will never know the difference.
Please make sure you have enough space for the temp table (_tablename_new).
UPDATE 2020-12-10 14:45 EST
If you are not doing backups on this server, then you could run
PURGE BINARY LOGS BEFORE CURDATE() - INTERVAL 5 DAY;

to keep the last 5 days worth of binary logs or if you want all the binary logs gone, then run
RESET MASTER;

WARNING !!!
Before doing that, find out if the server is running replication as a Master.
UPDATE 2020-12-10 16:05 EST
Since you are running pt-online-schema-change, you should run it like this
pt-online-schema-change --set-vars sql_log_bin=0 --alter &quot;ENGINE=InnoDB&quot;

This will just create a temp table defragmented. It just so happens that --analyze-before-swap is the default value. That means the temp table has ANALYZE TABLE executed against it before swapping old and new tables. This has the exact same effect as OPTIMIZE TABLE on an InnoDB table.
As mentioned in nbk's comment, you should make sure you have backups. You would also do yourself a world of good by setting up replication and doing the backups from the slave.