-
Notifications
You must be signed in to change notification settings - Fork 312
Limit size of ConsoleHost_history.txt file #537
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
Comments
I recommend setting these options:
To wrangle your existing history file to a reasonable size, try this script I created to optimize PSReadLine history. You will need to exit all PowerShell instances and then start a https://gist.github.com/rkeithhill/4099bfd8420eed0e6dbc You can run this script on your history file with |
@rkeithhill - your script has some serious problems - it doesn't read multi-line input correctly. |
Doh! I thought I fixed that. Let me check to see if I didn't update that Gist. |
Hmm, I'm stepping through the script in the VSCode debugger and so far I'm not seeing any problems reading multi-line input. Let me make sure I've got the rules right for multi-line input though. If a line is encountered that ends with a backtick then that line is part of multi-line input. And that same multi-line input continues until we hit a line that doesn't end with a backtick, right? Also on Linux, how do you handle duplicate entry checking? Case-sensitive, right? So gci and GCI will be duplicates but paths that varying only by case won't get eliminated by the dupe check. |
@lzybkr OK, spent time debugging this and comparing history files before and after. Found (and fixed) a few issues and updated the Gist.
All of these issues have been fixed. Try it again and see what you think. |
It looks like I had an old version and you fixed the problem I encountered on Mar 3, 2017. Maybe you should just add your script to this repo. |
Sure. Where should I put it? |
Hmm, so even though my profile sets the Set-PSReadlineOption -MaximumHistoryCount 10000 -HistorySearchCursorMovesToEnd -HistoryNoDuplicates -HistorySavePath $PSScriptRoot\PSReadLine_history.txt When I Huh? Is there a maximum value for MaximumHistoryCount parameter? If so, shouldn't the Set-PSReadlineOption validate the value? |
That would be a bug. There is some weirdness around setting that value from |
Also faced this issue. In my case the "ConsoleHost_history.txt" file was 3.19 GB in size! That's just insane! Anyone mind telling what that file is even used for? Is it important? I deleted it for now. And I'm guessing I'll have to look at it again in the future. |
Just like other shells (like bash), when you start a new shell, you can immediately use commands you entered from a previous session. For example, open a new instance of PowerShell, type |
Got the same exception for a different reason on macOS:
|
My ConsoleHost_history file was 3.7GB. Just how? |
@Omniusz - sorry about that - I think you hit a rare race condition which I had only heard about once before. See #524 - the symptom was different but I believe the fix is the same. |
I have just found a Scanning the file and it appears 10k blocks of the same line so something went a bit crazy. I just deleted the file and system returned to normal, but damn that was unexpected. |
Sorry about that @dennisroche. You're the third to report this issue, fortunately it is fixed in |
No problem; thanks for getting it fixed. |
I use PowerShell in Version 5.1.14393.2636, but i still have the issue "the limitation is not working". |
As mentioned above, there was a race condition that caused some history files to grow unreasonably. That race condition is fixed in all 2.0 versions. This issue remains open because there is still no limit to the size of the history file. |
Ok thanks, but do I have to update manually to version 2.0 or will the issue by fixed with windows updates? |
A version of PSReadLine 2.0 does ship in Windows 10 1809. It's nearly the same as beta3 I think, but I'm not sure as I'm not responsible for what ships in Windows. Older versions of Windows will likely not see updates to PSReadLine. |
I know this is an old incident, but have there been any thoughts on implementing a way to limit the size of the history file? "MaximumHistoryCount" is only how many lines are read from the file and put into your history. It has nothing to do with the file size, so the file will continue to get bigger forever. A multi-GB history file serves no purpose and is just a waste of space. |
Uh oh!
There was an error while loading. Please reload this page.
Recently, accessing command history via the up-arrow has been quite slow (3-5 seconds to respond), and today, when I opened PowerShell, the console was non-responsive and after about 3 mintues would throw the error below:
With little digging I found that the console history file found here:
had grown to 13MB and contained about 3 months of commands, and deleting the file fixed both issues.
How can the size of this file be moderated?
Environment data
PS version: 5.1.14393.1198
PSReadline version: 1.2
os: 10.0.14393.0 (rs1_release.160715-1616)
PS file version: 10.0.14393.0 (rs1_release.160715-1616)
The text was updated successfully, but these errors were encountered: